37

On a local development machine, I have a nginx reverse proxy like so:

server {
  listen 80;
  server_name myvirtualhost1.local;
  location / {
    proxy_pass http://127.0.0.1:8080;
}

server {
  listen 80;
  server_name myvirtualhost2.local;
  location / {
    proxy_pass http://127.0.0.1:9090;
}

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.

  • 1
    Consider starting a background job and letting the user check its status later. – Michael Hampton May 19 '16 at 12:39
48

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.

  • 3
    Dear random downvoter, a comment on what is bad about this practice would be nice. – k0pernikus Aug 11 '16 at 16:37
  • 7
    @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 '16 at 8:41
  • 2
    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 '16 at 10:21
  • 5
    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 Mintern Aug 30 '17 at 20:30
  • 3
    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 '17 at 0:32
9

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

  • 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 '18 at 5:04
  • @doz87 yes, it's just something for consideration – szeljic Oct 2 '18 at 8:28
  • This is really worth checking especially on my case that working with Magento under the AWS. Good point @szeljic – vnpnlz Oct 30 '18 at 8:23
  • Thanks bro, this works for me since I use AWS load balancer for distributing to my EC2 instance – Vũ Thành Tâm Dec 5 '18 at 7:47
  • 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 at 8:50
3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.