# 503 custom error page

**URL:** <https://www.ruby-forum.com/t/503-custom-error-page/215146>\
**Category:** NGINX\
**Created:** [December 23, 2011, 11:12am UTC](https://www.ruby-forum.com/t/503-custom-error-page/215146 "2011-12-23T11:12:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [December 23, 2011, 11:12am UTC](https://www.ruby-forum.com/t/503-custom-error-page/215146/1 "2011-12-23T11:12:17Z")

</div>

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:

> **[503 custom error page](https://forum.nginx.org/read.php?2,220418,220418#msg-220418)**
>
> 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 understa

---

<div class="post-metadata">

**Author:** ![djeyewater](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/71e660/32.png) [@djeyewater](https://www.ruby-forum.com/u/djeyewater)\
**Post date:** [December 23, 2011, 1:36pm UTC](https://www.ruby-forum.com/t/503-custom-error-page/215146/2 "2011-12-23T13:36:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![djeyewater](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/71e660/32.png) [@djeyewater](https://www.ruby-forum.com/u/djeyewater)\
**Post date:** [December 23, 2011, 3:39pm UTC](https://www.ruby-forum.com/t/503-custom-error-page/215146/3 "2011-12-23T15:39:16Z")

</div>

Thanks for the explanation, makes sense to me now.

Dave

Posted at Nginx Forum:

> **[Re: 503 custom error page](https://forum.nginx.org/read.php?2,220418,220436)**
>
> 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 understa

---

<div class="post-metadata">

**Author:** ![djeyewater](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/71e660/32.png) [@djeyewater](https://www.ruby-forum.com/u/djeyewater)\
**Post date:** [December 23, 2011, 4:16pm UTC](https://www.ruby-forum.com/t/503-custom-error-page/215146/4 "2011-12-23T16:16:25Z")

</div>

On Fri, Dec 23, 2011 at 7:35 AM, Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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.

> **[ScaleEngine is the Technical Video Streaming CDN Delivering Perfect Streams...](https://www.scaleengine.com/contact)**
>
> Video CDN, streaming live and on demand securely and reliably. Perfect streams to the world with our developer API, exact usage billing, and direct support
