Richard
Richard

Reputation: 65510

nginx: increase timeout to prevent 404 not found error?

I have a Django server running Gunicorn, and in front of that I have nginx. I serve static files directly from nginx, and pass other things through to Gunicorn.

I have some slow-running back-end queries, and I'm finding that nginx is quite often timing out before they return - so I see a 404 page.

Is there a way I can increase the timeout level?

This is my nginx conf file:

server {
    listen 443;
    client_max_body_size 4G;
    access_log /webapps/myapp/logs/nginx-access.log;
    error_log /webapps/myapp/logs/nginx-error.log;
    location /media/ {
        alias   /webapps/myapp/myapp/media/;
    }
    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        if (!-f $request_filename) {
            proxy_pass http://hello_app_server;
            break;
        }
    }

I think perhaps I need proxy_read_timeout, but I'm not sure from the docs.

Upvotes: 8

Views: 7610

Answers (1)

Adam Birds
Adam Birds

Reputation: 434

Try

proxy_read_timeout 120s;

Put that inside your proxy section.

The default is apparently 60s so try doubling and go from there.

Not too confident about it but i had something similar with a timeout in mysql today on a server at work and doubling that worked. Worth a try and hope it helps.

Upvotes: 11

Related Questions