uwsgi_next_upstream

The `uwsgi_next_upstream` directive specifies conditions under which the NGINX server will attempt to pass a request to the next server in a group when the current one fails.

Syntaxuwsgi_next_upstream error | timeout | invalid_header | http_status;
Defaultoff
Contexthttp, server, location
Arguments1+

Description

The uwsgi_next_upstream directive is utilized in the context of handling failures when communicating with upstream UWSGI servers. It allows you to configure specific response codes or conditions that would trigger a retry of the request on the next server in the upstream group. The values you can specify include common failure conditions such as timeout, invalid_header, and a range of HTTP status codes indicating errors (e.g., 502, 503, 504). This flexibility helps improve the reliability of web applications by providing fallback options in case of server issues.

When NGINX encounters an error while processing a UWSGI request that matches one of the designated failure conditions, it will automatically attempt to re-route the request to the next server defined in the uwsgi_pass directive. This can greatly enhance the resilience of your application by preventing temporary errors from impacting the end user experience. The parameters provided to the directive can be combined to provide a comprehensive set of retry strategies tailored to your specific application needs.

Config Example

location /app {
    uwsgi_pass backend;
    uwsgi_next_upstream error 502 503 504;
}

Make sure that the upstream servers can handle the same requests as the initial server to avoid inconsistent behavior.

The directive should only be used in the context of the uwsgi directives, such as uwsgi_pass, otherwise it has no effect.

If multiple upstream servers are unavailable, requests may enter a retry loop if not configured with proper exit conditions.

← Back to all directives