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
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:
http://wiki.nginx.org/HttpCoreModule#root
http://wiki.nginx.org/HttpCoreModule#alias
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.
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