Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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!!

share|improve this question

1 Answer 1

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?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.