uwsgi_next_upstream_tries

The 'uwsgi_next_upstream_tries' directive defines the number of upstream servers that NGINX will try to connect to in case of an error while communicating with the original upstream server in uWSGI mode.

Syntaxuwsgi_next_upstream_tries number;
Default0
Contexthttp, server, location
Arguments1

Description

The 'uwsgi_next_upstream_tries' directive is used to specify how many times NGINX should attempt to contact an alternative upstream server before failing a request. This directive works in conjunction with the uWSGI module and is applicable within the 'http', 'server', and 'location' contexts. When NGINX encounters a problem connecting to the designated upstream server—for instance, if the server is down, or if it returns HTTP error codes—it will try to connect to the next upstream server in its list of available servers up to the number specified by this directive.

By default, this directive is set to 0, which means that NGINX will not attempt any retries in case of a failed connection to the upstream server. Setting this directive to a value greater than zero (such as 1, 2, or even more) enables NGINX to handle temporary server issues more gracefully, allowing for potential service recovery without failing the request outright. This can enhance the resilience of applications when they encounter transient errors with upstream servers.

The value provided must be a positive integer that denotes the maximum number of retry attempts against the defined upstream servers. Users should be cautious when using this directive, as excessive retry attempts could lead to increased latency and resource usage if upstream servers are consistently failing.

Additionally, it's essential to monitor the health of upstream servers and consider using health checks to ensure NGINX only routes traffic to servers that are available and responsive.

Config Example

upstream myapp {
    server backend1.example.com;
    server backend2.example.com;
}

location / {
    uwsgi_pass myapp;
    uwsgi_next_upstream_tries 2;
}

Ensure the value for 'uwsgi_next_upstream_tries' is a positive integer; otherwise, NGINX will not attempt retries.

Excessive retries can lead to increased latency; monitor your upstream server's performance closely.

← Back to all directives