MYaser
MYaser

Reputation: 379

uWsgi nginx integration error

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

Upvotes: 1

Views: 7319

Answers (4)

kokociel
kokociel

Reputation: 529

I similarly had this problem for a combination of Django, uWSGI and nginx running behind CloudFront. It turned out for me that the routing table in CloudFront didn't behave as expected, so some of the callbacks weren't received.

Specifically, route "/" stole traffic from "*".

There was another issue where my Django server was running unexpected code; as a user logging in caused their User model to be changed, which I hadn't predicted for some reason. So yeah, don't rule out that your Django server might be legitimately busy, causing a timeout of the socket.

Upvotes: 0

Moamen
Moamen

Reputation: 706

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

Upvotes: 5

roberto
roberto

Reputation: 12933

It looks like you are using a distribution package instead of official uWSGI sources. Just load (after having installed it) the python plugin with plugin = python in your config

http://uwsgi-docs.readthedocs.org/en/latest/WSGIquickstart.html

Upvotes: 1

location / {  
    uwsgi_pass      unix:///var/run/uwsgi.sock;  
    include         uwsgi_params;  
    uwsgi_param     SCRIPT_NAME '';  
}

Upvotes: 0

Related Questions