proxy_intercept_errors

The `proxy_intercept_errors` directive is used to control whether NGINX intercepts errors from proxied servers. — NGINX HTTP Core

proxy_intercept_errors
httpserverlocation
Синтаксисproxy_intercept_errors on | off;
По умолчаниюoff
Контекстhttp, server, location
МодульNGINX HTTP Core
Аргументыflag

Описание

The `proxy_intercept_errors` directive in NGINX allows users to specify whether the server should handle error responses from proxied servers. When this directive is set to `on`, NGINX will intercept HTTP responses that indicate errors (like 404, 500, etc.) and process them according to the configured error handling settings. Conversely, if this directive is set to `off`, any error responses received from a proxied server will be passed directly to the client without any modification or handling by NGINX. This can be useful for implementing custom error pages or redirecting clients based on specific errors. This directive can be set in the `http`, `server`, or `location` contexts, making it versatile for various configuration scenarios. It is important to understand that setting this directive to `on` can lead to different behavior than expected, as the client will not see the original response from the proxied server unless you specifically configure error handling. Depending on your application architecture and how you want to manage errors presented to the user, the proper setting of this directive can be crucial.

Пример конфига

location /api {
    proxy_pass http://backend;
    proxy_intercept_errors on;
    error_page 404 /custom_404.html;
}

Ensure that you have defined custom error pages if `proxy_intercept_errors` is set to `on` to avoid serving default error pages.

When enabled, ensure your application's error handling strategy aligns with how NGINX will process errors.