Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase timeout for NGINX?

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

like image 534
Adam Strike Avatar asked Feb 17 '19 21:02

Adam Strike


People also ask

What is the default Nginx server timeout?

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.

How to increase request timeout to 300 seconds?

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; ...

How long does Nginx show activity on a post?

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.

Is Nginx the best choice for serving long-running requests?

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.


2 Answers

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

like image 52
Vinay Avatar answered Oct 16 '22 21:10

Vinay


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

like image 1
Emmanuel BRUNET Avatar answered Oct 16 '22 21:10

Emmanuel BRUNET