nginx error page and internal directives not working as expected
- by Romain
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 says error_page directives are not concerned by internal: 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!!