Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx 504 Gateway Timeout Error for Django

I am running a Django site on DigitalOcean using 1ClickInstallation image. Every thing worked fine but I got issue for 504 Gateway Timeout Error. I've tried multiple settings on blogs but not working. Following are my settings:

upstream app_server {
    server 127.0.0.1:9000 fail_timeout=0;

}


server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /home/django/django_project;
    index index.html index.htm;

    client_max_body_size 4G;
    server_name www.mydomain.com;


    keepalive_timeout 5;

    location ~*  \.(jpg|jpeg|png|gif|ico|css|js|woff2|woff|ttf)$ {
        expires 365d;
    }



    # Your Django project's media files - amend as required
    location /media  {
        alias /home/django/django_project/media/;
    }

    # your Django project's static files - amend as required
    location static/static-only {
        alias /home/django/django_project/static-only/; 
    }
    # Django static images
    location /static/django_project/images {
        alias /home/django/django_project/static-only/django_project/images/;
    }


    # Proxy the static assests for the Django Admin panel
    location /static/admin {
       alias /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin;
    }

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://app_server;

    }
}

I followed docs at following link http://nginx.org/en/docs/http/ngx_http_limit_req_module.html

Following is the result of "wget 127.0.0.1:9000"

enter image description here

but couldn't make sense that where exactly to add directives. Kindly advise.

like image 602
Shazia Nusrat Avatar asked Mar 05 '16 06:03

Shazia Nusrat


1 Answers

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; 
}
like image 124
Lukasz Dynowski Avatar answered Sep 30 '22 07:09

Lukasz Dynowski