How to increase timeout for NGINX?
Solution 1
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;
}
Solution 2
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
Adam Strike
Updated on July 09, 2022Comments
-
Adam Strike almost 2 years
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
likekeepalive_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
-
Adam Strike about 5 yearsWhat do you mean that it's not a secured option? Thanks for help btw :)
-
Adam Strike about 5 yearsAnd would I put that in
/etc/nginx/nginx.conf
? -
Emmanuel BRUNET about 5 yearsaccepting a large file to be downloaded is the same as accepting a large file uploading using this option ^^ .. may be a binary one .. with auto excecutable capabillities .. NGINX won't check that
-
Emmanuel BRUNET about 5 yearsyes in the /etc/nginx/nginx.conf in your sever section as stated
-
Adam Strike about 5 yearsIt's not a large file, just take a few minutes to generate?
-
Emmanuel BRUNET about 5 yearsto generate ? you must understand that a web server only transfers / parses http / https or other protocols frames . it does not "generate" data .. and should not !
-
Adam Strike about 5 yearsI don't have a server section in
nginx.conf
and I get an error when trying to add one. I do have multiple server section in my /sites-available/myappname, but that does not fix the problem. -
Emmanuel BRUNET about 5 yearsdifficult for me to check that .. without the source config code and without knowing your own environment (that you should not provide) . you have an include statement in your root configuration file .. just follow it and you'll find the right server configuration to apply what I proposed. By default in /etc/nginx/conf.d as I remember
-
Adam Strike about 5 yearsWhere exactly would I add this?
-
Adam Strike about 5 yearsMy conf.d file is empty and the web server doesn't generate the file, it's a flask application. :)
-
Emmanuel BRUNET about 5 yearsLet us continue this discussion in chat.
-
Satish Patro about 5 yearsyou have not added timeout in your answer
-
Ricardo Vargas almost 3 yearsFinally a solution that Works.