On Sun, Feb 19, 2012 at 01:22:34PM +0300, Nginx U. wrote:
return 503
location /error_docs {
internal;
alias /server/path/to/folder;
}
…
}
Will always return the Nginx default 503 page. Same applies to all status codes.
It’s not ignored, but returning error unconditionally in the
server context also prevents error_page processing from
working, as the “return 503” is again executed after error_page
internal redirect. That is, something like this happens:
Request comes for “/something”.
Server rewrites generate 503.
Due to error_page set the request is internally redirected to
/error_docs/custom503.html.
Server rewrites again generate 503.
As we’ve already did error_page redirection, nginx ignores
error_page set and returns internal error page.
}
location /error_docs {
internal;
alias /server/path/to/folder;
}
…
}
This doesn’t “return 503” for error_page processing, and hence it
works ok.
Another possible aproach is to use named location in error_page.
It won’t re-execute server rewrites (that is, rewrite module
directives, including the “return” directive, specified at server
level) and will work as well.
As we’ve already did error_page redirection, nginx ignores
error_page set and returns internal error page.
This then is the “bug”.
It SHOULD now return “/error_docs/custom503.html” with a 503 status
code.
I.E., work as it does when the error is issued within a location
context since once a user has set error_page, they would most likely
expect a matching status return to deliver what was set.
I assume there must be some technical road block but you guys are
supposed to be geniuses
Another possible aproach is to use named location in error_page.
It won’t re-execute server rewrites (that is, rewrite module
directives, including the “return” directive, specified at server
level) and will work as well.
Unfortunately, this doesn’t appear to work as expected either
Server {
# listen etc
…
error_page 503 = @sitedown;
return 503
location @sitedown {
root /server/path/to/folder;
# Don't you wish try_files could accept a single
On Sun, Feb 19, 2012 at 03:23:58PM +0300, Nginx U. wrote:
/error_docs/custom503.html.
4. Server rewrites again generate 503.
5. As we’ve already did error_page redirection, nginx ignores
error_page set and returns internal error page.
This then is the “bug”.
It SHOULD now return “/error_docs/custom503.html” with a 503 status code.
I.E., work as it does when the error is issued within a location
context since once a user has set error_page, they would most likely
expect a matching status return to deliver what was set.
This is not a bug. You instructed nginx to generate 503 on each
request which hits server rewrite phase, and it does what you
said.
On Sun, Feb 19, 2012 at 03:45:15PM +0300, Nginx U. wrote:
...
error_page 503 = @sitedown;
return 503
location @sitedown {
root /server/path/to/folder;
# Don't you wish try_files could accept a single parameter?
try_files $uri /custom503.html;
Unless you have $uri file, this will do an internal redirect to
/custom503.html, triggering the same 503 again. You have to
process request in the location in question to make things work.
Unfortunately, this doesn’t appear to work as expected either
try_files $uri /custom503.html;
Unless you have $uri file, this will do an internal redirect to
/custom503.html, triggering the same 503 again. You have to
process request in the location in question to make things work.
Thanks.
I got a working config where I first redirect to a location and issue
the 503 status there.
Now, don’t you really, really wish try_files could accept a single
parameter??
Your method will work if you only a few location blocks active to
which you can easily add the return directive.
The one I suggested works in my case where I have several location
blocks.
I have just put the relevant bits into a file and can include it when
I need to take the domain down.
It also allows for the inclusion of images, css. js and similar
resources.
alias /server/path/to/error_docs/folder;
}
}
#############
Your method will work if you only a few location blocks active to
which you can easily add the return directive.
You can nest all your location blocks in single location / { } block
(and you can put location / { } in location / { }). Just add “location
/ {” before start of other locations (except error page) and “}” after
them.
Also have you tried this one? Instead of plain “return 503;” in server
block:
server {
if ($uri !~ ^/error_page/) {
return 503;
}
…
}
Because even if “return 503” is capable of returning the page you
want, the css/js/image still won’t work.
Also have you tried this one? Instead of plain “return 503;” in server block:
No, I haven’t and don’t plan to at this time because I have a setup
that works fine as posted earlier with images, css etc all loading as
required.
As said, there isn’t one single answer as the Nginx config allows a
lot of flexibility and if you prefer a different setup, that’s just
fine.