When to use
Used to set the request resources and the server return time, to ensure that a request to occupy a fixed time, beyond the 504 timeout! This will ensure that a request takes too long.
Second, the main parameters
Use the Nginx server if you encounter timeou conditions, you can set the following parameters to use fastcgi:
Fastcgi_connect_timeout 75; Link
Fastcgi_read_timeout 600; Read
Fastcgi_send_timeout 600; Send a request
These two options.
Fastcgi_read_timeout refers to the timeout for the entire process that fastcgi processes send response to the nginx process
Fastcgi_send_timeout refers to the timeout for the entire process of sending a request to the FASTCGI process Nginx process
Both options default to seconds (s), can be manually specified as minutes (m), hours (h), etc.
third, other commonly used parameters and parameter description
Keepalive_timeout 600; Connection timeout, 1 minutes, can be set depending on the time required (for example, background import)
Proxy_connect_timeout 600; 1 minutes.
Proxy_read_timeout 600; 1 minutes.
Nginx Timeout Configuration parameter description:
Keepalive_timeout
Syntax keepalive_timeout timeout [header_timeout]
Default value 75s
Context HTTP Server location
Note The first parameter specifies the timeout for the Keep-alive connection to the client. The server will close the connection after this time. The optional second parameter specifies the time value in the response header keep-alive:timeout=time. This header enables some browsers to actively turn off the connection so that the server does not have to shut down the connection. Without this parameter, Nginx does not send the Keep-alive response header (although it is not the header that determines whether the connection is "keep-alive")
The values of two parameters may not be the same
Note how different browsers handle "keep-alive" headers
MSIE and Opera ignored the header of "keep-alive:timeout=<n>".
MSIE stay connected for about 60-65 seconds, then send TCP RST
Opera permanently maintains long connections
Mozilla keeps the connection alive for N plus about 1-10 seconds.
Konqueror Keep long connection n seconds
Proxy_connect_timeout
Syntax proxy_connect_timeout time
Default value 60s
Context HTTP Server location
Explains that the directive sets the connection timeout for upstream server, and it is important to remember that this timeout cannot exceed 75 seconds.
This is not the time to wait for the back end to return to the page, which is declared by Proxy_read_timeout. If your upstream server is up, but hanging live (for example, there are not enough threads to process the request, so put your request in the request pool for later processing), then this statement is useless because the connection to the upstream server has been established.
Proxy_read_timeout
Syntax proxy_read_timeout time
Default value 60s
Context HTTP Server location
Describes the read timeout that this directive sets with the proxy server. It determines how long the nginx will wait to get the requested response. This time is not the time to get the whole response, but the time of two reading operations.
Client_header_timeout
Syntax client_header_timeout time
Default value 60s
Context HTTP Server
Description specifies the timeout for waiting for the client to send a request header (for example, get/http/1.1). The timeout is counted only if the request header is not received in a read. If the client does not send anything within the timeout period, Nginx returns the HTTP status code 408 ("Request timed Out")
Client_body_timeout
Syntax client_body_timeout time
Default value 60s
Context HTTP Server location
Describes the read timeout for the request body set by this directive. The requested body is set to timeout only once in a readstep. After timeout, Nginx returns the HTTP status code 408 ("Request timed Out")
Lingering_timeout
Syntax lingering_timeout time
Default Value 5s
Context HTTP Server location
Note Lingering_close after the entry into force, before closing the connection, will detect whether the user sent data to the server, if more than lingering_timeout time after the data can not be read, directly close the connection; The connection must not be closed until the data on the connection buffer has been read and dropped.
Resolver_timeout
Syntax resolver_timeout time
Default value 30s
Context HTTP Server location
Indicates that the directive sets the DNS resolution timeout
Proxy_send_timeout
Syntax proxy_send_timeout time
Default value 60s
Context HTTP Server location
This specifies that the timeout for sending requests to the upstream server is set. The timeout setting is not for the entire send period, but during the two write operation. If the upstream does not receive new data after the timeout, Nginx closes the connection
Proxy_upstream_fail_timeout (Fail_timeout)
Syntax server address [fail_timeout=30s]
Default Value 10s
Context Upstream
Describes the parameters of the server directive under the upstream module, setting a upstream after a specified number of failed backend (max_fails), the back-end is not operational, default to 10 seconds
Iv. examples
Here's an example of an increase in the time-out period for nginx.
See if the time meets the requirements, three parameters in the Nginx.config:
- Fastcgi_connect_timeout 300;
- Fastcgi_send_timeout 300;
- Fastcgi_read_timeout 300;
The units above are seconds.
If you use a nginx agent, you can add it in the Block:
Proxy_connect_timeout 300s;
Proxy_send_timeout 300s;
Proxy_read_timeout 300s;
Become:
Location/foo {
Proxy_pass http://xxx.xxx.xxx.xxx:8080/foo;
Proxy_set_header Host $host;
Proxy_set_header x-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Proxy_connect_timeout 300s;
Proxy_send_timeout 300s;
Proxy_read_timeout 300s;
Access_log/var/log/nginx/access.foo.log main;
Error_log/var/log/nginx/error.foo.log;
}