How to disable timeout for nginx?

Solution 1:

It may not be possible to disable it at all, yet a feasible workaround is to increase the execution time. On a nginx tutorial site, it was written:

If you want to increase time-limit for all-sites on your server, you can edit main nginx.conf file:

vim /etc/nginx/nginx.conf

Add following in http{..} section

http {
     fastcgi_read_timeout 300;
     proxy_read_timeout 300;
}

and reload nginx' config:

sudo service nginx reload

I have used a rather large value that is unlikely to happen, i.e. 999999 or using time units, to one day via 1d.

Beware that setting the value to 0 will cause a gateway timeout error immediately.

Solution 2:

If you are using AWS, and Load Balancer, you should edit Idle timeout. I think default is 60 seconds


Solution 3:

It is possible to increase the timeout for nginx, to add to @k0pernikus 's answer, the following can be added to your location block:

        location /xyz {
         proxy_read_timeout 1800;
         proxy_connect_timeout 1800;
         proxy_send_timeout 1800;
         send_timeout 1800;
        }

Here 1800 is in seconds.

After changing the config, verify the syntax with:

nginx -t -c /some/path/nginx.conf

Then reload nginx with:

nginx -s reload

Solution 4:

I've been fighting with nginx 502 timeout error and could not solve the issue. However, it happened to be gunicorn causing the timeout error. So you might also need to check your fastcgi settings.

For gunicorn it's:

gunicorn wsgi:application --timeout 300