How to Increase Request Timeout in NGINX

How to Increase Request Timeout in NGINX

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

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *