Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django+Nginx+uWSGI = 504 Gateway Time-out

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!

like image 411
Leachy Peachy Avatar asked Jul 12 '11 22:07

Leachy Peachy


People also ask

How do I fix nginx 504 Gateway Timeout error?

A 504 error means nginx has waited too long for a response and has timed out. There might be multiple reasons for the problem. Possible fixes include: Increasing the nginx proxy_read_timeout default of five minutes to be longer, for example, to 10 minutes.

Is nginx required for uWSGI?

Can I then ditch NGINX? uWSGI could be used as a standalone web server in production, but that is not it's intentional use. It may sound odd, but uWSGI was always supposed to be a go-between a full-featured web server like NGINX and your Python files.

What is uWSGI Django?

uWSGI is a fast, self-healing and developer/sysadmin-friendly application container server coded in pure C. See also. The uWSGI docs offer a tutorial covering Django, nginx, and uWSGI (one possible deployment setup of many). The docs below are focused on how to integrate Django with uWSGI.


1 Answers

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).

like image 118
freb Avatar answered Sep 27 '22 20:09

freb