![Everything you need to know about NGINX Timeouts](/image/original/a52e80d4-18e6-11ef-881c-002590a5fecf.png)
Everything you need to know about NGINX Timeouts
NGINX is a popular multipurpose server that links parts of the external/internal network and also gives access to the dynamic data and files. Here in this writing, we will talk specifically about the NGINX timeouts and how to handle everything correctly by disabling and setting various timeouts. Timeouts are essential if speaking about the configuration aspect because they specify the period during which the server waits for a specific event prior to its termination. They are extremely important and influence the stability of the servers as well as stoppage of the resource exhaustion. So, if that topic sounds interesting, then we will share all the practical recommendations regarding timeouts.
Fundamentals of NGINX Timeouts
Here are a couple of the fundamentals of NGINX timeouts:
- send_timeout – this is related to the max time frame when the response is sent to the client (according to the default setting, it is 60). It is crucial for the stoppage of response delays and managing of slow clients.
- client_body_timeout – this timeout characterizes the max time frame that is needed for the reading body of the request (60 according to the default). In case this request is not received then the connection is closed and such a thing is needed for dealing with huge post or file uploads.
- keepalive_timeout – that is the max time frame for the client connection to be on the server (the initial parameter is 75 default while the second one is 60 default).
- client_header_timeout – this is the max time frame that is needed for the header reading of the request (as for the default parameter then it is 60). When the header isn’t received during a certain time, the connection will be closed. This variant of timeout is needed for the prevention of partial or slow requests.
- lingering_timeout – this cycle (default 30) can repeat for the max time in case lingering_close is on. This parameter sets the max time frame for more data from the client to arrive.
Low-level TCP Timeout in NGINX
If talking about the low level, then the listen directive has keepalive and this parameter is needed for the configuration of the TCP socket. By setting it off or on, we are utilizing an essential keepalive mechanism.
We can also use a colon-separated list:
- keepintvl – sets TCP_KEEPINTVL
- keepidle – sets TCP_KEEPIDLE
- keepcnt – sets TCP_KEEPCNT
By ignoring any of the mentioned parameters, you are leaving the default settings.
proxy_* Timeouts in NGINX
Here we share only 3 of the most frequent timeout values for NGINX, and they are the following:
- proxy_send_timeout – max time frame that is needed to send request (default 60)
- *_connect_timeout – max time frame needed to connect to the server (as a rule under 75, but the default parameter is 60)
- *_read_timeout – max time frame to read the response of the proxied server (default 60)
fastcgi_* Timeouts in NGINX
When speaking about the settings of the FastCGI server, there can be pointed out several categories such as:
- fastcgi_send_timeout – this is a characteristic of the max time frame for sending requests of FastCGI server (default 60)
- *_connect_timeout – this is characteristic of the max time frame for the connection to the server (as a rule under 75, default 60)
- *_read_timeout – max time frame to read the response from the server (default 60)
memcached_* Timeouts in NGINX
With memcached_* timeouts, the options are rather similar to those examples that we have already shared in the article, so they are the following:
- memcached_send_timeout – this is characteristic of the max time frame for sending the request of the Memcached server (60)
- *_connect_timeout – the max time frame for the connection with the server (as a rule under 75, default 60)
- *_read_timeout – the max time frame for the reading response of the server (default 60)
Disabling Common NGINX Timeouts
When generally examining this topic, you can effortlessly utilize the list of settings in the server or http block for disabling the common timeouts, let’s review a couple of the basic samples:
keepalive_timeout 1d
send_timeout 1d
client_body_timeout 1d
*_header_timeout 1d
proxy_send_timeout 1d
*_connect_timeout 1d
*_read_timeout 1d
fastcgi_read_timeout 1d
*_connect_timeout 1d
*_send_timeout 1d
memcached_read_timeout 1d
*_connect_timeout 1d
*_send_timeout 1d
Summary
Of course, with NGINX you have a huge variability of alternatives with the use of which you can adjust various timeouts. However, when you change the crucial ones, it can significantly influence the performance characteristics. Hope this article was helpful for your case and you get all the important insights about the NGINX Timeouts.