nginx won't serve an error_page in a subdirectory of the document root

Posted by Brandan on Server Fault See other posts from Server Fault or by Brandan
Published on 2012-10-18T16:08:37Z Indexed on 2012/10/18 17:04 UTC
Read the original article Hit count: 193

Filed under:
|

(Cross-posted from Stack Overflow; could possibly be migrated from there.)

Here's a snippet of my nginx configuration:

server {
    error_page 500 /errors/500.html;
}

When I cause a 500 in my application, Chrome just shows its default 500 page (Firefox and Safari show a blank page) rather than my custom error page.

I know the file exists because I can visit http://server/errors/500.html and I see the page. I can also move the file to the document root and change the configuration to this:

server {
    error_page 500 /500.html;
}

and nginx serves the page correctly, so it's doesn't seem like it's something else misconfigured on the server.

I've also tried:

server {
    error_page 500 $document_root/errors/500.html;
}

and:

server {
    error_page 500 http://$http_host/errors/500.html;
}

and:

server {
   error_page 500 /500.html;
   location = /500.html {
       root /path/to/errors/;
   }
}

with no luck.

Is this expected behavior? Do error pages have to exist at the document root, or am I missing something obvious?


Update 1: This also fails:

server {
    error_page 500 /foo.html;
}

when foo.html does indeed exist in the document root. It almost seems like something else is overwriting my configuration, but this block is the only place anywhere in /etc/nginx/* that references the error_page directive.

Is there any other place that could set nginx configuration?

© Server Fault or respective owner

Related posts about nginx

Related posts about custom-errors