4

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:

  1. GET /Home
  2. nginx passes the query to Python
  3. I'm simulating an application bug to get the 502 error code
  4. nginx tries to return /InternalError from its error_page rule
  5. 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!!

Romain
  • 41
  • 3

1 Answers1

2

There's not much sense in using "~*" for /internalerror location, plain location would do.

You're getting 404 because /InternalError file is missing. Did you intend to serve such requests from uwsgi backend?

sendmoreinfo
  • 1,742
  • 12
  • 33