uwsgi_intercept_errors

The `uwsgi_intercept_errors` directive controls whether NGINX intercepts errors returned by uWSGI applications.

Syntaxuwsgi_intercept_errors on | off;
Defaultoff
Contexthttp, server, location
Argumentsflag

Description

The uwsgi_intercept_errors directive, when enabled (set to 'on'), allows NGINX to intercept specific error responses from a uWSGI server and handle them according to predefined policies rather than passing them directly to the client. This typically includes standard HTTP error codes like 404 and 500, allowing users to configure custom error pages, logging, and other behaviors when such responses are encountered. Conversely, when set to 'off', NGINX will return the uWSGI response directly to the client without modification, which may not provide a user-friendly experience for erroneous requests.

This directive can be utilized within the http, server, or location contexts, making it versatile for application-specific needs and deployment configurations. In contexts where developers want a consistent user experience even in the face of errors from the backend application, setting this directive to 'on' is beneficial, enabling a more professional and tailored response for users in case of errors, such as serving HTML error pages instead of raw error messages from the application.

Parameters accepted by this directive include a boolean value, either 'on' to enable error interception or 'off' to disable it. It is important to note that this directive applies specifically to uWSGI responses and the behavior it controls can be integral to managing user-facing errors effectively.

Config Example

location /myapp {
    uwsgi_pass myapp_backend;
    uwsgi_intercept_errors on;
    error_page 404 /custom_404.html;
    error_page 500 502 503 504 /custom_50x.html;
}

If the directive is set to 'off', custom error handling will not function, and raw responses from uWSGI may confuse users.

Ensure proper error pages are defined when intercepting errors to avoid showing default NGINX error pages. When adding custom error pages, make sure they exist and are correctly referenced.

← Back to all directives