Home Tech How To Edit the Directory To Fix Nginx Request Timeout

How To Edit the Directory To Fix Nginx Request Timeout

If you have ever had to work with servers, you will agree that Nginx is one of the most widely used servers in the world, along with Apache. As a result, there may be a number of options to assist when we are stuck using this server. However, the nginx request timeout error may be tricky to fix.

In this post, I’ll teach you how to increase requests timeout on Nginx, which is a really convenient and helpful feature. This gives you additional options when customizing Nginx and adjusting it to the demands of your numerous apps or websites.

Let’s get to it!

How To Edit the Directory To Fix Nginx Request Timeout

Requests are timed out after 60 seconds by default. In some circumstances, it may be required to boost it to reply to long requests, such as database queries. The catch is that the NGINX server will deliver a 504 error for exceeding the timeout.

Because we usually have numerous VirtualHosts in the system, you’ll need to edit each one’s configuration file. Users can find these files in the   /etc/nginx/sites-available folder.

Within the server directory, we must change the values for proxy_connect_timeout, proxy_read_timeout, and proxy_send_timeout.

Below is an example of what it may look like:

proxy_read_timeout 360;
proxy_connect_timeout 360;
proxy_send_timeout 360; 

In the above code, the values for the different timeouts are expressed in second (360s) and equate to 6 minutes. You can modify this value to suit your need.

Once this is done, save changes to your code and close the editor.

My recommendation is to double-check that the syntax used is correct. You can do this by running the script:

nginx -t

If it is all fine you will need to restart Nginx for the changes to take effect. use the following code to restart Nginx:

systemctl restart nginx

How to Edit the Directory For All Projects and SItes to Fix nginx Request Timeout

If you have multiple projects, it may be redundant to perform the fix on individual projects. A global fix may be more appropriate. Here is how to accomplish a global edit.

Open up the Nginx configuration file using this code:

nginx request timeout

Once in make the same kind of modifications you made earlier:

proxy_read_timeout 360;
proxy_connect_timeout 360;
proxy_send_timeout 360;

Following the same steps you took earlier, you will have to save the changes you have made and restart the server before the changes can take effect.

The Need for Speed on the Internet

When a person browses the web, the aim is to do it as quickly as possible. Nginx is one of the quickest web servers available in this regard, which is the reason many websites pick it over Apache.

Additionally, people prefer Nginx because of the configuration freedom it provides. Not to say that Apache isn’t capable, but Nginx allows us to customize nearly anything and with far more freedom…

The timeout of requests made on servers is one of the things we may control in Nginx. Knowing how to regulate access to these programs is critical for making optimal use of the network resources and, as a result, impacting loading speed.

So, while speed isn’t everything on the Internet, it does have a significant impact on your user experience.

NGINX Request Timeout Related FAQs

If you have run into an Nginx request timeout issue here are some related questions you would need to be answered.

How can I change the timeout in NGINX?

We have discussed this all through the article so just scroll up for more details.

What is the NGINX keep-alive timeout?

Keepalive is a directive in Nginx that keeps the connection open for a specified requests number to the server or for the duration of the timeout period. 10,000 idle connections require just 2.5 MB of RAM, according to Nginx engineers, demonstrating that Nginx is very effective for the handling of idle connections due to keepalive connections.

What benefits does keepalive have in Nginx?

Creating additional TCP connections may chew up a lot of resources, including CPU and memory. Keeping a connection active in Nginx, on the other hand, might help you save money; that is why keepalive is generally recommended for HTTPS connections. Enabling the keepalive feature can help you improve your website’s user experience and speed.

What is the default for Nginx timeout?

Timeouts in HTTP 30 seconds is the default setting.  NGINX Unit will respond with an HTTP error 408 or Request Timeout as soon as the timeout is exceeded.

What number of connections can NGINX handle?

Every open connection in NGINX equals at least one and frequently two open files. We’re effectively stating that each worker can open up to 4096 files by keeping the max number of connections to 4096.

What is the actual function of proxy _ send _ timeout in Nginx?

For the backend servers, there are 3 timeouts that may be defined in the Nginx doc: proxy_connect_timeout Sets the timeout for connecting to a proxied server. Note that this timeout is normally limited to 75 seconds.

What do you do when the Nginx connection is slow?

Raise the maximum amount of keepalive requests a client may make over a given connection from the default of 100, and increase the keepalive timeout to permit the keepalive connection to remain open longer, resulting in the subsequent requests becoming faster.

In Nginx server, how does the reverse proxy work?

With the reverse proxy, a client’s request is accepted, forwarded to an Upstream server (one that can finish the request), and the server’s answer is returned to a client. When the proxy server receives an invalid response from the source server, Nginx upstream problems occur.

What is NGINX and how reverse proxies work?

Final Thoughts

I have covered all the possible fixes for Nginx request timeout errors in this article. These are not errors to get you alarmed in your servers, and you do not need to pay a “professional” to fix it. A few simple edits to your files should get you up and running.

If there are any hacks I have omitted, please let me know what they are in the comment section. I look forward to hearing from you.