503 custom error page

Maxim Dounin mdounin at mdounin.ru
Fri Dec 23 12:35:57 UTC 2011


Hello!

On Fri, Dec 23, 2011 at 05:11:57AM -0500, djeyewater wrote:

> I'm trying to get a maintenance page working for my site. I added the
> following to the server block:
> 
> error_page 503 /maintenance.html;
> return 503;
> 
> This serves 503 but with default nginx 503 error page.
> 
> The following works okay, but I don't understand why the above doesn't
> show the custom 503 page?

The error_page in question does internal redirect to 
"/maintanance.html", which in turn returns 503 due to "return 503" 
at sever level.

I.e. there is no way to reach /maintanance.html, and hence nginx 
returns builtin page.

Using "return 503" at location level will work, assuming you'll 
define special location for /maintenance.html without the return. 
i.e.:

    location / {
        error_page 503 /maintenance.html;
        return 503;
    }

    location /maintanance.html {
        # no "return 503" here
    }


> error_page 503 @503;
> return 503;
> location @503 {
> 	try_files /maintenance.html =503;
> }

This works as named location's doesn't re-execute server level 
rewrite directives (i.e. no "return 503" here as well).

Maxim Dounin



More information about the nginx mailing list