recursive_error_pages

The `recursive_error_pages` directive controls whether error pages are processed recursively.

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

Description

The recursive_error_pages directive can be set to either 'on' or 'off', allowing users to enable or disable recursive processing of error pages. When this directive is set to 'on', if a request encounters an error page (like a 404 Not Found), NGINX will attempt to process that error page through the same configuration, potentially allowing further error pages to be served if they encounter their own errors.

This directive is useful for simplifying error handling in complex site configurations where error pages themselves may rely on additional configuration settings. For example, if an error page is also misconfigured, rather than just returning an error immediately, NGINX will try to handle it using the same configuration context, which can lead to clearer error displays for users. However, care should be taken to avoid creating loops where error pages continually reference each other without resolution.

The directive can be placed within any context of http, server, or location, giving a wide scope of control over how different levels of error handling are managed. It should be noted that enabling recursive error pages may expose additional overhead and complexity in scenarios where error handling can result in additional server load.

Config Example

http {
    recursive_error_pages on;

    server {
        error_page 404 /custom_404.html;
    }
}

Enabling recursive_error_pages can result in unexpected recursive loops if error pages are also misconfigured. Be cautious with complex configurations involving multiple layers of error handling.

It is advisable to test error pages thoroughly when using this directive to ensure proper functioning and to avoid excessive server loads.

← Back to all directives