proxy_next_upstream_timeout

The 'proxy_next_upstream_timeout' directive sets the timeout for attempts to connect to the next upstream server in a proxy scenario.

Syntaxproxy_next_upstream_timeout time;
Default1s
Contexthttp, server, location
Arguments1

Description

The proxy_next_upstream_timeout directive is used in NGINX to specify the maximum amount of time allowed to wait for the next upstream server after a previous connection attempt has failed. This is particularly useful when dealing with load balancing across multiple backend servers, as it dictates how long NGINX will wait before retrying another server in the upstream block upon encountering specified error conditions or a timeout.

When a request fails due to a timeout or other defined criteria, NGINX can automatically attempt to connect to an alternative upstream server. The proxy_next_upstream_timeout directive allows administrators to control how long such a retry will be attempted. By adjusting this timeout value, you can optimize the responsiveness of your application, striking a balance between waiting for a potentially slow server and quickly failing over to a healthy server.

The timeout value is specified in a time format compatible with NGINX, such as seconds, minutes, or hours (e.g., '30s' for 30 seconds). Setting this directive at different contexts, such as http, server, or location, can provide granular control based on the application's requirements.

Config Example

location /api {
    proxy_pass http://backend;
    proxy_next_upstream_timeout 5s;
}

Ensure that the timeout value is sufficient for your upstream servers to respond, otherwise frequent timeouts might occur.

Be aware of the interaction between proxy_next_upstream_timeout and other related directives, such as proxy_connect_timeout.

Not setting a value may lead to default behavior that may not be suitable for your application needs.

← Back to all directives