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

server {
  listen 80;
  server_name myvirtualhost1.local;
  location / {

server {
  listen 80;
  server_name myvirtualhost2.local;
  location / {

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

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.

| improve this answer | |
  • 5
    Dear random downvoter, a comment on what is bad about this practice would be nice. – k0pernikus Aug 11 '16 at 16:37
  • 8
    @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
  • 6
    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 '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

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

| improve this answer | |
  • 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
  • 1
    @foo it's on the LoadBalancer page on AWS. the Description tab and the Attributes section. Idle timeout. – szeljic Aug 26 at 13:23

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
| improve this answer | |
  • 2
    about each timeout nginx.org/en/docs/http/… – TRiNE Apr 15 at 7:02
  • 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 at 20:12
  • 1
    @MaxCarroll, I don't think config files generally support variables. Set wouldn't work as it is not bash. – Vasantha Ganesh K Aug 9 at 10:58

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
| improve this answer | |

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.