Hi,
I’m trying to deliver a custom 503 page for all requests the server
receives but with the following config it doesn’t work.
server {
listen 81;
server_name localhost;
error_log /var/log/nginx/error.log debug;
root /usr/share/nginx/html;
location / {
return 503;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
I get a 503 response but the 50x.html page is not used even though it is
present in /usr/share/nginx/html/50x.html. I see no error in the error
log even in debug mode.
What is wrong with this config?
Regards,
Dennis
Hi,
Nginx reads from top to bottom, just like you. In your example, you are
returning 503 (an action) before instructing to use your custom error
page.
Just need to put your instructions first, then your actions…like so:
error_page 500 502 503 504 /50x.html;
location = /50x.html { root /usr/share/nginx/html; }
location / { return 503; }
-Skyler
Posted at Nginx Forum:
Hello!
On Wed, Jul 31, 2013 at 02:51:43AM -0400, skchopperguy wrote:
Hi,
Nginx reads from top to bottom, just like you. In your example, you are
returning 503 (an action) before instructing to use your custom error page.
Just need to put your instructions first, then your actions…like so:
error_page 500 502 503 504 /50x.html;
location = /50x.html { root /usr/share/nginx/html; }
location / { return 503; }
No, config directives order doesn’t matter in general. There are
some exceptions (like rewrite module directives order, or order of
locations with regular expressions), but the configuration in
question is fine and has no problems with directives order.
Most likely, the problem was somewhere else (e.g. conflicting
server{} block in the configuration, or original message author
just forgot to reload the configuration after changes).
–
Maxim D.
http://nginx.org/en/donation.html