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;
fastcgi_pass 127.0.0.1:8080;
}
Edit: What I have is not working :)
In
http
nginx section (/etc/nginx/nginx.conf) add or modify:In
server
nginx section (/etc/nginx/sites-available/your-config-file.com) add these lines:In
php
file in the case 127.0.0.1:9000 (/etc/php/7.X/fpm/pool.d/www.conf) modify:I hope help you.
For those using nginx with unicorn and rails, most likely the timeout is in your
unicorn.rb
fileput a large timeout in unicorn.rb
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.
Proxy timeouts are well, for proxies, not for FastCGI...
The directives that affect FastCGI timeouts are
client_header_timeout
,client_body_timeout
andsend_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.HTH.
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.