Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a NodeJS application to which I forward requests using proxy_pass. When the NodeJS application is off, I want to display a custom error page. So I put a 5xx.html file into /var/www/some-folder/errors and forward errors to it.

Now when I try to access while the NodeJS server is off, the 502 error is raised and nginx correctly returns the 5xx.html page.

Now according to nginx.conf (see below), I would assume that if I request, it gets forwarded through the location ^~ /errors/ directive to /var/www/some-folder and then to /errors/5xx.html. But instead of getting the 5xx.html page, I get the default nginx 404 Not Found page.

Why can't I access the 5xx.html page directly? Thank you.


server {

   location / {
       // some settings

   location ^~ /errors/ {
       root /var/www/some-folder;

   error_page 502 503 504 505 /errors/5xx.html;

share|improve this question
up vote 2 down vote accepted

You can't access the page directly because you specified in your configuration to not allow such requests.


See the nginx documentation:

Specifies that a given location can only be used for internal requests. For external requests, the client error 404 (Not Found) is returned.

share|improve this answer
Oh God... That's what happens when you just copy something from somewhere without even knowing what it does. :) Thank you. I will accept your answer shortly. – Zabri Jun 9 '14 at 12:50

Your Answer


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.