Stack Exchange Network

Stack Exchange network consists of 182 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers. Visit Stack Exchange

Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.

Sign up to join this community

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Yet if I debug my application, the response may be delayed for an infinite amount of time, yet after 30 seconds I get:

504 Gateway Time-out

as a response.

How can I disable the timeout and have my reverse proxy wait forever for a response? And I like the setting to be global, so that I do not have to set it for each proxy.

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.

@kb. It's funny as that I am the OP and just posted the most workable workaround as an answer, while waiting for a real solution ^^ – k0pernikus Oct 17, 2016 at 8:41 Haha, I completely missed that you were OP. But your answer is the correct one, you could make it even more clear (for future googlers like me) that there is no way to disable it. =) – kb. Oct 17, 2016 at 10:21 Thanks for the info about 0 not working! Note that you can specify time units with readable suffixes, so you could use a value like 1d. – Brandon Aug 30, 2017 at 20:30 I have added both that and proxy_connect_timeout 600; to the nginx.conf file, but the timeout is still on 60 seconds. Anything else I should try? – andreszs Oct 27, 2017 at 0:32 I guess you've been downvoted because you should never touch /etc/nginx/nginx.conf. In case of update, this file might be erased, and anyway it's a bad practice. Read the file carefully and you'll see in the http section, it includes include /etc/nginx/conf.d/*.conf;. So, this is where you should put your own "custom" configuration: create a file, like /etc/nginx/conf.d/global_custom.conf (or whatever name you want), and put your directives there. You can find so many misleading informations on the web... – Olivier Pons May 31, 2022 at 10:34

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
                is there anyway to set a variable as 1800 and then assign that variable, I tried using set, but it didnt work
– Max Carroll
                Aug 7, 2020 at 20:12
                @MaxCarroll, I don't think config files generally support variables. Set wouldn't work as it is not bash.
– Vasantha Ganesh
                Aug 9, 2020 at 10:58
                I understand why this was down voted but maybe if the answer was updated to explain its use case, it would be more useful. Although this doesn't go to answer the OP, it is something useful to consider if you are using ELB as there is a limit on how long they will keep a connection open also.
– doz87
                Oct 2, 2018 at 5:04
                This is really worth checking especially on my case that working with Magento under the AWS. Good point @szeljic
– MuntingInsekto
                Oct 30, 2018 at 8:23
                This deserves all the upvotes - any AWS users will still be limited to 60 seconds regardless of their NGINX settings without this
– Aphire
                Jun 13, 2019 at 8:50
                @foo it's on the LoadBalancer page on AWS. the Description tab and the Attributes section. Idle timeout.
– szeljic
                Aug 26, 2020 at 13:23

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