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.
For example, you want to increase request timeout to 300 seconds. Then you need to add proxy_read_timeout, proxy_connect_timeout, proxy_send_timeout directives to http or server block. Here the http block allows the changes in all server in NGINX.
Essentially, the “404 error” indicates that your or your visitor's web browser was connected successfully to the website server or the host. However, it was unable to locate the requested resource, such as filename or any specific URL.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With