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

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including 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. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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