proxy_next_upstream_tries
The `proxy_next_upstream_tries` directive controls the number of attempts to communicate with upstream servers if a prior request fails.
Description
The proxy_next_upstream_tries directive specifies the maximum number of tries that NGINX will make to communicate with the upstream servers before returning an error. It essentially helps in load balancing by setting a retry limit that is applied when the request made to the upstream server does not succeed due to specified failure conditions. These conditions may include the server being unavailable, timeouts, or other errors.
When the directive is set, NGINX will attempt to retry the request to another server in the defined upstream group up to the number specified by this directive. If the maximum number of tries is reached, NGINX will then send an error message back to the client. This feature can enhance availability and resilience of services, especially in cluster deployments where some servers might become temporarily unresponsive.
The behavior of this directive is influenced by the proxy_next_upstream directive, which defines which failure scenarios should trigger a retry. It is important to balance the number of tries in resource-constrained environments, as excessive retries can lead to degraded performance due to unnecessary load on upstream servers.
Config Example
location /api {
proxy_pass http://backend;
proxy_next_upstream_tries 3;
}Setting the value to a very high number can lead to increased latency and resource consumption.
If not paired with appropriate proxy_next_upstream settings, retries may not occur as expected due to incorrect configuration of failure conditions.