proxy_connect_timeout
The proxy_connect_timeout directive sets the timeout for establishing a connection with a proxied server. — NGINX HTTP Core
Описание
The `proxy_connect_timeout` directive specifies the time limit for establishing a successful connection from the NGINX server to a proxied server. This is particularly useful in scenarios where the proxied server may be experiencing high load or is unresponsive. If the connection cannot be established within the specified timeout period, NGINX will return an error to the client, effectively preventing it from hanging indefinitely. The directive can be defined within different contexts such as `http`, `server`, and `location`, allowing granular control over timeout settings at varying scopes of configuration. Setting this timeout helps to improve failover handling and can assist in managing resource allocation effectively, ensuring that NGINX does not waste time on unresponsive upstream endpoints. The timeout value is typically specified in the format of time units (e.g., `10s`, `1m`).
Пример конфига
http {
proxy_connect_timeout 30s;
server {
location / {
proxy_pass http://backend;
}
}
}The timeout is only applicable during the connection establishment phase and does not affect how long data transfer takes after a connection is established.
Setting a very low timeout might lead to premature disconnections, especially if the upstream server is slow to respond.