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 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 http://some.address.com 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 http://some.address.com/errors/5xx.html, 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.

nginx.conf

server {
   server_name some.address.com;

   location / {
       // some settings
       proxy_pass http://127.0.0.1:8084/;
   }

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

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

}
share|improve this question

1 Answer 1

up vote 2 down vote accepted

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

        internal;

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 at 12:50

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.