简体   繁体   中英

nginx+uwsgi+django, Error 502 when deploy multi-apps, help me

The whole thing works well when there is only one django project, but when i create another django project and want to add it to nginx with the previous one, only one can work , the other one show 502 error.

The nginx config:

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 "";
    }  
}

the 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

In the end, i visit 119.254.35.221:80 and 119.254.35.221:81, only one of them(may be port 80 or 81) works well, the other one show ERROR:502.

Help me , i'm gonna crazy..

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

I follow the official method to solve this, but is there any workaround here?

Hosting multiple apps in the same uWSGI process is not the best approach (from a security and ease of configuration point of view). Having multiple uWSGI instances (one for app) is the best solution combined with the uWSGI Emperor to manage them.

By the way, if you want to work with multiple interpreters, you may need to add -vhost-host to the option as your virtual host key should be HTTP_HOST and not SERVER_NAME (as the port is not specififed in this variable)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM