Django+Nginx+uWSGI = 504 Gateway Time-out

Leachy Peachy picture Leachy Peachy · Jul 13, 2011 · Viewed 13k times · Source

I am running Ubuntu 10.04, Django 1.3, Nginx 0.8.54 and uWSGI 0.9.7.

Both Nginx and uWSGI load without error. However, when you access my site, it sits for a LONG time and then eventually loads a "504 Gateway Time-out" error.

Here is my Nginx Virtual Host conf file:

server {
listen          80;
server_name     www.mysite.com mysite.com;
error_log       /home/mysite/log/error.log;
access_log      /home/mysite/log/access.log;

location / {
    auth_basic  "Restricted";
    auth_basic_user_file    /home/mysite/public/passwd;
    include uwsgi_params;
    uwsgi_pass unix:///home/mysite/public/myapp.sock;
}

location /media {
    alias /home/mysite/public/myapp/media;
}


error_page  401  /coming_soon.html;

location /coming_soon.html {
    root /home/mysite/public/error_pages/401;
}

location /401/images {
    alias /home/mysite/public/error_pages/401/images;
}

location /401/style {
    alias /home/mysite/public/error_pages/401/style;
}

}

My site log shows this:

SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request / !!!

My error log show this:

upstream timed out (110: Connection timed out) while reading response header from upstream

I have two other sites on this server with the same configuration and they load PERFECTLY.

Has anyone else encountered this problem? There are several threads on here that are similar to my issue and I've tried several of those solutions but nothing seems to work.

Thank you in advance for your help!

Answer

freb picture freb · Aug 14, 2012

That error is produced when requests exceed the NGINX uwsgi_read_timeout setting. After NGINX exceeds this limit it closes the socket and then uWSGI tries to write to the closed socket, producing the error that you see from uWSIG.

Make sure your NGINX timeouts are at least as high as uWSGI timeouts (HARAKIRI_TIMEOUT).