By sheats

2009-02-18 17:01:26 8 Comments

I am running Django, FastCGI, and Nginx. I am creating an api of sorts that where someone can send some data via XML which I will process and then return some status codes for each node that was sent over.

The problem is that Nginx will throw a 504 Gateway Time-out if I take too long to process the XML -- I think longer than 60 seconds.

So I would like to set up Nginx so that if any requests matching the location /api will not time out for 120 seconds. What setting will accomplish that.

What I have so far is:

    # Handles all api calls
    location ^~ /api/ {
        proxy_read_timeout 120;
        proxy_connect_timeout 120;

Edit: What I have is not working :)


@Jose Carlos Ramos Carmenates 2017-01-30 20:14:03

In http nginx section (/etc/nginx/nginx.conf) add or modify:

keepalive_timeout 300s

In server nginx section (/etc/nginx/sites-available/ add these lines:

client_max_body_size 50M;
fastcgi_buffers 8 1600k;
fastcgi_buffer_size 3200k;
fastcgi_connect_timeout 300s;
fastcgi_send_timeout 300s;
fastcgi_read_timeout 300s;

In php file in the case (/etc/php/7.X/fpm/pool.d/www.conf) modify:

request_terminate_timeout = 300

I hope help you.

@utdev 2018-03-06 12:06:18

Would anything "bad" happen if I change the time to 10000 seconds?

@Jose Carlos Ramos Carmenates 2018-03-06 15:06:44

Not happen nothing bad, but your service wait more time. You can change it value as you want.

@Pavel Kalashnikov 2015-12-09 00:55:39

If you use unicorn.

Look at top on your server. Unicorn likely is using 100% of CPU right now. There are several reasons of this problem.

  • You should check your HTTP requests, some of their can be very hard.

  • Check unicorn's version. May be you've updated it recently, and something was broken.

@zgoda 2009-02-18 19:34:13

Proxy timeouts are well, for proxies, not for FastCGI...

The directives that affect FastCGI timeouts are client_header_timeout, client_body_timeout and send_timeout.

Edit: Considering what's found on nginx wiki, the send_timeout directive is responsible for setting general timeout of response (which was bit misleading). For FastCGI there's fastcgi_read_timeout which is affecting the fastcgi process response timeout.


@sheats 2009-02-19 15:42:31

The answer was the fastcgi_read_timeout -- thanks!

@Homer6 2012-07-17 18:50:18

For anyone using uwsgi and having this error, uwsgi_read_timeout 600; fixed my problem.

@jeffkee 2012-08-02 20:35:22

My question here would be (as a server admin amateur) where do I go to change this? httpd.conf file?

@jeffkee 2012-08-02 21:37:28

If it helps, mine was at /etc/nginx/ at Media Temple's DV system.

@Sam Grondahl 2013-10-17 18:09:03

Abdo gives a nice way to debug. If you still have trouble, you might need to increase the max client message size in nginx.conf (client_max_body_size **M;)

@JazzCat 2016-01-14 15:44:00

Increasing the timeout imho is not a proper solution.

@Stan Zeez 2016-07-12 10:19:32

Yes, uwsgi_read_timeout 600; fixed my problem too in: flask + uwsgi + nginx

@Abdo 2012-12-11 15:48:33

For those using nginx with unicorn and rails, most likely the timeout is in your unicorn.rb file

put a large timeout in unicorn.rb

timeout 500

if you're still facing issues, try having fail_timeout=0 in your upstream in nginx and see if this fixes your issue. This is for debugging purposes and might be dangerous in a production environment.

upstream foo_server {
        server fail_timeout=0;

@ZiggyTheHamster 2013-09-17 23:19:43

I think that people downvoted it because this is about Django, however your answer fixed my gateway timeout issue with Rails + Unicorn :)

Related Questions

Sponsored Content

2 Answered Questions

[SOLVED] Nginx 502 Bad Gateway. Solved by increasing buffer. Why?

  • 2013-10-23 10:44:16
  • Dominic Woodman
  • 16942 View
  • 13 Score
  • 2 Answer
  • Tags:   php nginx fastcgi

9 Answered Questions

[SOLVED] Where can I find the error logs of nginx, using fastcgi and django

11 Answered Questions

[SOLVED] Node.js + Nginx - What now?

  • 2011-02-15 20:49:02
  • Van Coding
  • 331703 View
  • 941 Score
  • 11 Answer
  • Tags:   node.js nginx concept

1 Answered Questions

0 Answered Questions

fastcgi-mono-server4 and nginx not working

1 Answered Questions

[SOLVED] Nginx 504 gateway timeout after 60 seconds

  • 2013-01-18 13:15:18
  • Leon van der Veen
  • 8362 View
  • 5 Score
  • 1 Answer
  • Tags:   php nginx fastcgi

3 Answered Questions

[SOLVED] Deploying django under a sub-URL with Nginx/Fastcgi

1 Answered Questions

[SOLVED] Nginx / FastCGI crashing on me all the time

  • 2012-01-12 00:38:52
  • rposky
  • 1401 View
  • 0 Score
  • 1 Answer
  • Tags:   mono nginx fastcgi

1 Answered Questions

Help to set up nginx+fastcgi webserver for django

2 Answered Questions

[SOLVED] How do I run more than one Django site on a single server using fastcgi?

  • 2009-04-23 00:00:22
  • Jason Champion
  • 511 View
  • 1 Score
  • 2 Answer
  • Tags:   django nginx fastcgi

Sponsored Content