修改成以下内容:
upstream backend{
server 127.0.0.1:9701 weight=1;
server 127.0.0.1:9702 weight=2;
}
server {
listen 8000;
server_name 127.0.0.1;
access_log /var/log/nginx/myblog_access.log;
error_log /var/log/nginx/myblog_error.log;
charset utf-8;
client_max_body_size 75M;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering off;
#Backend自己随便起的,但是要保证和upstream后面的名一致
proxy_pass http://backend;
}
}
server {
listen 9701;
server_name 127.0.0.1
access_log /var/log/nginx/logindemo_access.log;
error_log /var/log/nginx/logindemo_error.log;
charset utf-8;
client_max_body_size 75M;
root /aproject/djangoblogtest;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:9001;
uwsgi_read_timeout 60;
}
location /static/ {
expires 30d;
autoindex on;
add_header Cache-Control private;
alias /aproject/djangoblogtest/static/;
}
}
server {
listen 9702;
server_name 127.0.0.1
access_log /var/log/nginx/logindemo_access.log;
error_log /var/log/nginx/logindemo_error.log;
charset utf-8;
client_max_body_size 75M;
root /bproject/djangoblogtest;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:9002;
uwsgi_read_timeout 60;
}
location /static/ {
expires 30d;
autoindex on;
add_header Cache-Control private;
alias /bproject/djangoblogtest/static/;
}
}
然后在服务器根目录下,找到/aproject/djangoblogtest/uwsgi.ini,并设置以下内容:
[uwsgi]
socket = 127.0.0.1:9001
chdir = /aproject/djangoblogtest
wsgi-file = djangoblogtest/wsgi.py
master = True
processes = 4
threads = 2
#设置此参数,有一个主进程
master=True
#守护进程的方式运行,log日志存在此log文件里
deamonize=/var/log/uwsgi/blog_project.log
#主进程id写入文件里
pidfile= /var/log/nginx/uwsgi.pid
#退出时,清理环境
vacuum = True
reload-mercy = 10
max-requests = 5000
limit-as = 512
buffer-size = 30000
在服务器根目录下,新建文件夹bproject,然后将同一个项目上传到bproject目录中,在项目根目录下新建文件uwsgi.ini(路径:/bproject/djangoblogtest/uwsgi.ini),并设置以下内容:
[uwsgi]
socket = 127.0.0.1:9002
chdir = /bproject/djangoblogtest
wsgi-file = djangoblogtest/wsgi.py
master = True
processes = 4
threads = 2
#设置此参数,有一个主进程
master=True
#守护进程的方式运行,log日志存在此log文件里
deamonize=/var/log/uwsgi/blog_project.log
#主进程id写入文件里
pidfile= /var/log/nginx/uwsgi.pid
#退出时,清理环境
vacuum = True
reload-mercy = 10
max-requests = 5000
limit-as = 512
buffer-size = 30000
项目部署好之后,重启nginx
service nginx restart
将两个项目使用各自的uwsgi.ini同时启动,访问即可。