fastcgi_intercept_errors
The `fastcgi_intercept_errors` directive configures NGINX to intercept errors from FastCGI responses for custom error handling.
Description
The fastcgi_intercept_errors directive works in conjunction with FastCGI by controlling how NGINX handles any errors returned by the FastCGI server, such as 4xx or 5xx HTTP status codes. When set to 'on', NGINX will capture these error responses, allowing you to define custom error pages or perform additional processing instead of passing the original FastCGI error response back to the client directly. This is particularly useful in scenarios where you want to display user-friendly error messages or implement specific error recovery mechanisms.
The directive takes a boolean flag as its argument, which can be either 'on' or 'off'. When 'on', any error responses from the FastCGI server (like those with status codes in the 400 or 500 range) can be handled by specific error page configurations defined in the NGINX configuration. When set to 'off', the default behavior allows NGINX to return the FastCGI response as is, including any error messages. The directive can be utilized within the 'http', 'server', or 'location' contexts, providing flexibility in placement depending on the desired scope of error handling configuration.
Config Example
location /app {
fastcgi_pass backend;
fastcgi_intercept_errors on;
fastcgi_index index.php;
include fastcgi_params;
}Remember to define custom error pages when intercepting errors, otherwise users may receive no content or default error messages.
This directive does not affect non-FastCGI responses; ensure you configure other error handling for different types of backends if applicable.