[Fixed]-Nginx 504 Gateway Timeout Error for Django

14👍

I found the solution as I was trying to make changes in /etc/nginx/sites-available/django-project. But I needed to add following lines in /etc/nginx/nginx.conf the global settings for Nginx. Lines I’ve added are:

http {
    ...
    proxy_connect_timeout   10;
    proxy_send_timeout      15;
    proxy_read_timeout      20;
}

I have a small website hosted and this one above settings are enough. But others may set their settings according to their needs.

15👍

If you are using uwsgi with django, then you might add uwsgi_read_timeout directive to nginx’s config file at location place

location / { 
    uwsgi_read_timeout 120; 
}

6👍

I know I’m late to the party here but after trying many of these suggestions (and others) I eventually found the timeout for me was occurring from my DNS – if you’re using Amazon load balancers they have an “Idle timeout” set at 120s default.

Leave a comment