nginx + uwsgi + django,部署多应用程序时出错502,帮助我

时间:2012-09-28 05:56:05

标签: django nginx uwsgi

当只有一个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

我按照官方方法解决了这个问题,但这里有解决方法吗?

1 个答案:

答案 0 :(得分:0)

在同一个uWSGI进程中托管多个应用程序并不是最好的方法(从安全性和易于配置的角度来看)。拥有多个uWSGI实例(一个用于app)是与uWSGI Emperor结合使用的最佳解决方案。

顺便说一句,如果您想使用多个解释器,您可能需要将-vhost-host添加到该选项,因为您的虚拟主机密钥应该是HTTP_HOST而不是SERVER_NAME(因为此变量中未指定端口)