How to Increase Request Timeout in NGINX

1. Open the nginx.conf file in a text editor.

2. Find the http section and add the following line:

proxy_read_timeout 600;

3. Save the file and restart the nginx service.

4. Test the new timeout setting by making a request to the server.

Increase or set request timeout in nginx; Through this tutorial, we will learn how to increase or set request timeout in Nginx.

By default, the NGINX request timeout is set to 60 seconds. Sometimes we need to increase the request timeout in NGINX to handle long running requests. NGINX will give a “504: Gateway Timeout” error if we do not increase the request timeout value. 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

Just follow the following steps to increase request timeout in NGINX:

  • 1 – Open NGINX configuration file
  • 2 – Increase Request Timeout in NGINX
  • 3 – Restart NGINX

1 – Open NGINX configuration file

First of all, Open the terminal and execute the following command on command line to open NGINX configuration file in a text editor:

sudo vi /etc/nginx/nginx.conf

Important Note:- NGINX file may be located at /usr/local/nginx/conf , /etc/nginx , or /usr/local/etc/nginx depending on your installation.

2 – Increase Request Timeout in NGINX

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;
   ...
}

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; 
   ...
}

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; 
   ...
}

3 – Restart NGINX

Then, execute the following command on the command line to restart Nginx server:

sudo nginx -t

If there are no errors, so execute the following command to restart NGINX server:

sudo service nginx reload #debian/ubuntu
systemctl restart nginx #redhat/centos

Conclusion

Through this tutorial, we have learned how to increase or set request timeout in Nginx.

Recommended Linux Tutorials

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Contact
San Vito Al Tagliamento 33078
Pordenone Italy
Item added to cart.
0 items - 0.00
Open chat
Scan the code
Hello 👋
Can we help you?