503 custom error page

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?

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

Thanks

Dave

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,220418,220418#msg-220418

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 D.

Thanks for the explanation, makes sense to me now.

Dave

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,220418,220436#msg-220436

On Fri, Dec 23, 2011 at 7:35 AM, Maxim D. [email protected]
wrote:

The following works okay, but I don’t understand why the above doesn’t
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

}

I’ve done this with 403 and allow/deny so that the world sees
maintenance page, but developers can keep working. Create a second
directory with your maintenance view.

error_page 403 /403.html;
location = /403.html {
root /home/site_maintenance;
allow all;
}
location = /maintenance.png {
root /home/site_maintenance;
allow all;
}

Then for the control of the actual site directory:

location / {
# let internal subnet keep developing
allow a.b.c.d;
# everyone else triggers 403
deny all;
root /home/site;
index index.php;
try_files $uri $uri/ @handler;
}

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

Stefan C.
http://scaleengine.com/contact

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs