I am using Python, Flask, uWSGI and NGINX to host a web server. One of the functions involves generating a file for the user which can take up to a minute or two. On this action I keep getting a 504 timeout from NGINX. I tried to change some config variables in /etc/nginx/nginx.conf
like keepalive_timeout
but that didn't work.I also tried to add the following to /etc/nginx/conf.d/timeout.conf
:
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
and then I reloaded with systemctl reload nginx
but it didn't change anything.
How do I increase the length of time before the request times out? Thanks for any help
By default, requests timeout is 60 seconds. In some cases, it is necessary to increase it to respond to long requests like database queries and so on. The catch is that if the timeout is exceeded, the NGINX server will return a 504 error.
If you want to increase request timeout to 300 seconds, then add proxy_read_timeout, proxy_connect_timeout, proxy_send_timeout directives to http or server block http { ... proxy_read_timeout 300; proxy_connect_timeout 300; proxy_send_timeout 300; ...
I think default is 60 seconds Show activity on this post. It is possible to increase the timeout for nginx, to add to @k0pernikus 's answer, the following can be added to your location block: Here 1800 is in seconds.
NGINX is one of the best choices for serving long-running requests because it has a robust architecture. However, you might need to increase your request timeout to ensure that NGINX can easily handle these heavy loads.
Add the following directives at the end of the 'http' section to increase the timeout limit to 180 seconds (3 minutes):
http {
<...>
include /etc/nginx/conf.d/.conf;
proxy_send_timeout 180s;
proxy_read_timeout 180s;
fastcgi_send_timeout 180s;
fastcgi_read_timeout 180s;
}
Source : https://support.plesk.com/hc/en-us/articles/115000170354-An-operation-or-a-script-that-takes-more-than-60-seconds-to-complete-fails-on-a-website-hosted-in-Plesk-nginx-504-Gateway-Time-out
I faced the same problem .. I've found a workaround telling nginx to accept a certain amount of data over the default one. Not trying to manage the timeout itself but changing the amount of data accepted in the transaction did the trick.
server {
client_max_body_size 5M; # or more ^^
}
but it's really not a secured option .. it works, but take care doing this.
moreover if you are using a reverse proxy WSGI gateway (Php for example) .. the underlayrer mechanism may take precedence over that
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