Search code examples
configurationnginxwebserver

nginx: Is it possible to have an 'catch all' error_page?


When looking at the documentation for nginx's error_page directive, it seems that one has to manually list out every possible status code that nginx (or an upstream server) could return.

For example:

error_page   404          /404.html;
error_page   502 503 504  /50x.html;
error_page   403          http://example.com/forbidden.html;
error_page   404          = @fetch;

Is there anyway of producing a wildcard for ALL status codes that are not specified directly... For example:

error_page   404          /404.html;
error_page   5xx          /50x.html;

or

error_page   404          /404.html;
error_page   502 503 504  /50x.html;
error_page   @catchall    /5xx.html;

Solution

  • It is not possible.

    Moreover, it is not recommended to blindly list all codes, as

    • nginx allows to redefine all response codes, including ones you don't really want to redefine except in a few very specific situations (e.g. you don't normally want to redefine 304 (Not Modified), and probably not 302 (Found) unless there are very specific reasons);
    • redefining some of the error codes might cause more harm than good (e.g. redefining 400 (Bad Request) is a bad idea).