# Multiple error\_pages in one directory - with one location - not possible?

**URL:** <https://www.ruby-forum.com/t/multiple-error-pages-in-one-directory-with-one-location-not-possible/210118>\
**Category:** NGINX\
**Created:** [July 31, 2011, 2:56pm UTC](https://www.ruby-forum.com/t/multiple-error-pages-in-one-directory-with-one-location-not-possible/210118 "2011-07-31T14:56:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [July 31, 2011, 2:56pm UTC](https://www.ruby-forum.com/t/multiple-error-pages-in-one-directory-with-one-location-not-possible/210118/1 "2011-07-31T14:56:43Z")

</div>

Hi,

maybe i’m to stupid or missing something, but actually i try to setup a  
set  
of custom error\_pages. To keep it simple, i put them all into one  
directory  
and named them like the error i want to catch with them.

From the examples, i found setups like this:  
error\_page 404 /404.html;  
error\_page 502 503 504 /50x.html;

but since i don’t want them to be in the root of my virtual host, i put  
them into a different directory (outside of root). For that reason, i  
created a config like this:  
error\_page 503 /status-503.html;  
error\_page 403 /status-403.html;  
location = /status-503.html {  
root /var/www/statuspages;  
}  
location = /status-403.html {  
root /var/www/statuspages;  
}

and put a page named “status-503.html” intoo the statuspages dir. This  
works so far. But i would like to keep the locations as less as  
possible.  
So i tried the following:

error\_page 503 /status/503.html;  
error\_page 403 /status/403.html;  
location = /status {  
root /var/www/statuspages;  
}

But surprise, surprise, it didn’t work. I got a 404 error. Of course i  
have renamed the status-xxx.html pages to xxx.html, too. I also tried it  
with ^~ /status/, = /status/ and things like error\_page 503  
@status/503.html  
and location @status - with no success.

At the end i would like to have some internal location or something like  
that  
to avoid conflicts with real existing directorys - if possible. And just  
one  
location for my error pages.

Is that possible at all or should i just use multiple locations and  
everything  
is fine…?

Thanks and regards,  
Sven

---

<div class="post-metadata">

**Author:** ![Sven\_SDarkmanS\_Mich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e99b99/32.png) [@Sven\_SDarkmanS\_Mich](https://www.ruby-forum.com/u/Sven_SDarkmanS_Mich)\
**Post date:** [July 31, 2011, 3:15pm UTC](https://www.ruby-forum.com/t/multiple-error-pages-in-one-directory-with-one-location-not-possible/210118/2 "2011-07-31T15:15:51Z")

</div>

Hello!

On Sun, Jul 31, 2011 at 02:53:45PM +0200, Sven ‘Darkman’ Michels wrote:

[…]

> But surprise, surprise, it didn’t work. I got a 404 error. Of course i  
> have renamed the status-xxx.html pages to xxx.html, too. I also tried it

Path to file is produced as + . In your case is  
“/status/503.html”, so expected file path is  
“/var/www/statuspages/status/503.html”. Do you actually have this  
file?

From what you wrote it looks like you instead have  
“/var/www/statuspages/503.html” file. Using “alias” directive  
instead of “root” should resolve your problem.

See here for more information:

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

Note well: nginx should log error to error\_log if it isn’t able to  
find requested file; looking into error\_log is always a good idea.

Maxim D.

---

<div class="post-metadata">

**Author:** ![Sven\_SDarkmanS\_Mich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e99b99/32.png) [@Sven\_SDarkmanS\_Mich](https://www.ruby-forum.com/u/Sven_SDarkmanS_Mich)\
**Post date:** [July 31, 2011, 3:44pm UTC](https://www.ruby-forum.com/t/multiple-error-pages-in-one-directory-with-one-location-not-possible/210118/3 "2011-07-31T15:44:20Z")

</div>

Hi,

Am 31.07.2011 15:15, schrieb Maxim D.:

> Path to file is produced as + . In your case is  
> “/status/503.html”, so expected file path is  
> “/var/www/statuspages/status/503.html”. Do you actually have this  
> file?

Nope…

> From what you wrote it looks like you instead have  
> “/var/www/statuspages/503.html” file. Using “alias” directive  
> instead of “root” should resolve your problem.

Yeah, you’re right 😕 My fault. Didn’t think about because i copied it  
from another block i use, but since there is only one status page,  
the setup was slightly different and worked.

> Note well: nginx should log error to error\_log if it isn’t able to  
> find requested file; looking into error\_log is always a good idea.

Well, i did that. But it only logs directory index of  
“/var/www/webroot/” is  
forbidden" - nothing about the missing error page. But i got a 404 in  
the  
accesslog, but i thought this was due to the fact that the location  
didn’t work.

Anyway, changeing root to alias and location ^~ /status/ { internal;  
alias /var/www/statuspages/; } did the trick.

Thanks a lot for the enlightenment 😉

Best regards,  
Sven
