Nginx – uWsgi nginx integration error

djangonginxuwsgi

I am using uWsgi to deploy my django site here is my uWsgi.ini:

[uwsgi]
socket=/var/run/uwsgi.sock
virtualenv=/root/edupalm/env/
chdir=/root/edupalm/edupalm
master=True
workers=8
pidfile=/var/run/uwsgi-master.pid
max-requests=5000
module=edupalm.wsgi:application

and using nginx, here is my configuration:

server {
    listen       9000;
    server_name  162.243.146.127;
    access_log  /var/log/nginx/edupalm_access.log;
    error_log   /var/log/nginx/edupalm_error.log;

    location /static/ {
        alias /root/edupalm/edupalm/static/;
    }
    location / {
        uwsgi_pass      unix:///var/run/uwsgi.sock;
    }

}

but I am having 502 Bad Gateway

here is the logs:

nginx:

2013/11/26 08:31:09 [error] 1758#0: *57 upstream prematurely closed connection while reading response header from upstream, client: 197.160.112.183, server: 162.243.146.127, request: "GET /admin HTTP/1.1", upstream: "uwsgi://unix:///var/run/uwsgi.sock:", host: "162.243.146.127:9000"

uwsgi:

-- unavailable modifier requested: 0 --

nginx is running on user www-data and uwsgi is running as root

Best Solution

It's advisable to use new user for your project, not root

The problem is in configuration, you should to add

plugin=python

for permissions it's better to use www-data user/group:

uid = www-data
gid = www-data
chmod-socket = 777
chown-socket = www-data
Related Question