Last updated on October 20th, 2020 at 03:56 am
By default, NGINX request timeout is 60 seconds. Sometimes you may need to increase request timeout in NGINX to serve long-running requests. If you don’t increase request timeout value NGINX will give “504: Gateway Timeout” Error. Here’s how to increase request timeout in NGINX using proxy_read_timeout, proxy_connect_timeout, proxy_send_timeout directives to fix 504 Gateway Timeout error.
How to Increase Request Timeout in NGINX
Here are the steps to increase request timeout in NGINX.
1. Open NGINX configuration file
Open terminal and run the following command to open NGINX configuration file in a text editor.
$ sudo vi /etc/nginx/nginx.conf
NGINX file may be located at /usr/local/nginx/conf , /etc/nginx , or /usr/local/etc/nginx depending on your installation.
Bonus Read : Increase File Upload Size in NGINX
2. Increase Request Timeout in NGINX
If you want to increase request timeout to 300 seconds, then add proxy_read_timeout, proxy_connect_timeout, proxy_send_timeout directives to http or server block
http{ ... proxy_read_timeout 300; proxy_connect_timeout 300; proxy_send_timeout 300; ... }
In the above case, the request timeout will be increased for all servers in your NGINX configuration file.
If you want to increase request timeout only for a specific server or subdomain, then add proxy_read_timeout, proxy_connect_timeout, proxy_send_timeout directives for its server block.
server{ ... proxy_read_timeout 300; proxy_connect_timeout 300; proxy_send_timeout 300; ... }
If you want to increase request timeout only for specific folder or URL, then add proxy_read_timeout, proxy_connect_timeout, proxy_send_timeout directives for that specific location block.
location /upload { ... proxy_read_timeout 300; proxy_connect_timeout 300; proxy_send_timeout 300; ... }
For large values, you can also specify time units such as 1d for 1 day.
Bonus Read : How to Hide Server Information in NGINX
3. Restart NGINX
Finally, run the following command to check syntax of your updated config file.
$ sudo nginx -t
Bonus Read : How to Setup NGINX Load Balancer
If there are no errors, run the following command to restart NGINX server.
$ sudo service nginx reload #debian/ubuntu $ systemctl restart nginx #redhat/centos
That’s it! Hopefully the above tutorial will help you increase request timeout in NGINX.
Ubiq makes it easy to visualize data in minutes, and monitor in real-time dashboards. Try it today!
Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI & software development.