nginx error page and internal directives not working as expected
Posted
by
Romain
on Server Fault
See other posts from Server Fault
or by Romain
Published on 2011-02-02T23:48:00Z
Indexed on
2012/04/05
11:31 UTC
Read the original article
Hit count: 348
I'd like to setup my nginx server to return a specific error page on HTTP 50x status codes, and I'd like this page to be unavailable by a direct request from users (e.g., http//mysite/internalerror).
For that, I'm using nginx's internal
directive, but I must be missing something, as when I put that directive on my /internalerror
location, nginx returns a custom 404 error (which isn't even my own 404 error page) when a page crashes.
So, to summarize, here's what seems to happen:
- GET /Home
- nginx passes the query to Python
- I'm simulating an application bug to get the 502 error code
- nginx tries to return /InternalError from its
error_page
rule - because of the
internal
rule, it finally fails back to a custom 404 error code <-- why? the documentation sayserror_page
directives are not concerned byinternal
: http://wiki.nginx.org/HttpCoreModule#internal
Here's an extract from nginx.conf with a few comments to point things out:
error_page 404 /NotFound;
error_page 500 502 503 504 =500 /InternalError; # HTTP 500 Error page declaration
location / {
try_files /Maintenance.html $uri @pythonbackend;
}
location @pythonbackend {
include uwsgi_params;
uwsgi_pass unix:///tmp/uwsgi.sock;
}
location ~* \.(py|pyc)$ { # This internal location works OK and returns my own 404 error page
internal;
}
location /__Maintenance.html { # This one also works fine
internal;
}
location ~* /internalerror { # This one doesn't work and returns nginx's 404 error page when I trigger an error somewhere on my site
internal;
}
Thanks very much for your help!!
© Server Fault or respective owner