当只有一个 django 项目时,整个事情运行良好,但是当我创建另一个 django 项目并想将它与前一个项目一起添加到 nginx 时,只有一个可以工作,另一个显示 502 错误。
nginx配置:
server{
listen 80;
root /root/www;
server_name 119.254.35.221;
location /{
uwsgi_pass 127.0.0.1:8000;
include uwsgi_params;
uwsgi_param UWSGI_SCRIPT www.wsgi;
uwsgi_param UWSGI_CHDIR /root/www;
uwsgi_param UWSGI_PYHOME /root/www;
uwsgi_param SCRIPT_NAME "";
}
}
server{
listen 81;
root /root/www1;
server_name 119.254.35.221;
location / {
uwsgi_pass 127.0.0.1:8000;
include uwsgi_params;
uwsgi_param UWSGI_SCRIPT www1.wsgi;
uwsgi_param UWSGI_CHDIR /root/www1;
uwsgi_param UWSGI_PYHOME /root/www1;
uwsgi_param SCRIPT_NAME "";
}
}
uwsgi.ini:
[uwsgi]
uid = 500
listen=200
master = true
profiler = true
processes = 8
logdate = true
socket = 127.0.0.1:8000
pidfile = /root/www/www.pid
daemonize = /root/www/www.log
enable-threads = true
memory-report = true
limit-as = 6048
And I create two project:
1, www: django-admin.py startproject www
2, www1: django-admin.py startproject www1
Then I start nginx and uwsgi:
1, ngxin
2, uwsgi --ini uwsgi.ini --vhost
最后,我访问了 119.254.35.221:80 和 119.254.35.221:81,只有一个(可能是 80 或 81 端口)运行良好,另一个显示 ERROR:502。
救救我,我要疯了。。
server {
listen 80;
server_name customersite1.com www.customersite1.com;
access_log /var/log/customersite1/access_log;
location / {
root /var/www/customersite1
uwsgi_pass 127.0.0.1:3031;
include uwsgi_params;
}
}
server {
listen 80;
server_name customersite2.com www.customersite2.com;
access_log /var/log/customersite2/access_log;
location / {
root /var/www/customersite2
uwsgi_pass 127.0.0.1:3032;
include uwsgi_params;
}
}
server {
listen 80;
server_name pippo.com;
access_log /var/log/pippo/access_log;
location / {
root /var/www/pippohome
uwsgi_pass 127.0.0.1:3033;
include uwsgi_params;
}
}
Now you have to run the customer's applications (you can use rc.local or upstart or whetever you want) with a different uid and a limited (if you want) address space for each socket:
uwsgi --uid 1001 -w customer1app --limit-as 128 -p 3 -M -s 127.0.0.1:3031
uwsgi --uid 1002 -w customer2app --limit-as 128 -p 3 -M -s 127.0.0.1:3032
uwsgi --uid 1003 -w django3app --limit-as 96 -p 6 -M -s 127.0.0.1:3033
我按照官方的方法来解决这个问题,但是这里有什么解决方法吗?