5

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?

voretaq7
  • 79,345
  • 17
  • 128
  • 213
Brandan
  • 151
  • 4

2 Answers2

5

Try adding

proxy_intercept_errors on;

or

fastcgi_intercept_errors on;

in server block depending of your configuration.

This sort of config is working ok:

  error_page   500 502 503 504  /500.html;
    location = /500.html {
        root   /home/static/pages;
    }
Andrei Mikhaltsov
  • 2,987
  • 1
  • 22
  • 31
  • That didn't seem to help. See Update 1 in my question. It almost seems like it's hard-coded to `/500.html`. – Brandan Oct 18 '12 at 16:46
  • Does your application really generate 500 error? Did you checked in firebug that HTTP code returned is really 500? – Andrei Mikhaltsov Oct 18 '12 at 16:52
  • Yes. Safari's Web Inspector indicates a 500, I can look in the Rails log and see that it's responding with a 500, and the nginx access.log agrees: `"GET / HTTP/1.1" 500 10 "-"`. – Brandan Oct 18 '12 at 17:13
  • 2
    The answer is correct in general, but exact directive to use may vary depending on backend protocol used. E.g. for fastcgi apps it would be [fastcgi_intercept_errors](http://nginx.org/r/fastcgi_intercept_errors). – Maxim Dounin Oct 18 '12 at 18:10
0

try this:

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

this should send http status 200 so browser will display your page. With default status (which is 500) browser probably shows its own error page and ignores your content, even if it's send by server.

Regards, Adam

Adam
  • 1