# "error\_page"& "return" bug?

**URL:** <https://www.ruby-forum.com/t/error-page-return-bug/217006>\
**Category:** NGINX\
**Created:** [February 19, 2012, 11:23am UTC](https://www.ruby-forum.com/t/error-page-return-bug/217006 "2012-02-19T11:23:15Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![Nginx\_U](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@Nginx\_U](https://www.ruby-forum.com/u/Nginx_U)\
**Post date:** [February 19, 2012, 4:24pm UTC](https://www.ruby-forum.com/t/error-page-return-bug/217006/21 "2012-02-19T16:24:35Z")

</div>

On Sun, Feb 19, 2012 at 10:20 PM, Nginx U. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ```
> }
> }
> 
> ```
> 
> }
> 
> Finally I promise 🙂

…so, the method above is better than using location / { } block? I’m  
confused now.

#############  
server {  
error\_page 503 /error\_docs/custom503.html;  
location / {  
return 503;  
…normal configs…  
}  
location /error\_docs/ {  
internal;  
alias /server/path/to/error\_docs/folder;  
}  
}  
#############

–  
O\< ascii ribbon campaign - stop html mail - [www.asciiribbon.org](http://www.asciiribbon.org)

---

<div class="post-metadata">

**Author:** ![Nginx\_U](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@Nginx\_U](https://www.ruby-forum.com/u/Nginx_U)\
**Post date:** [February 19, 2012, 6:35pm UTC](https://www.ruby-forum.com/t/error-page-return-bug/217006/22 "2012-02-19T18:35:05Z")

</div>

On Mon, Feb 20, 2012 at 12:19 AM, Nginx U. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> On 19 February 2012 19:44, Edho A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > 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.

For completeness, the version without if (single page - all requests  
returning 503, least overhead etc - put other static resources on  
different domain/server):

server {  
# listen etc  
…  
error\_page 503 @503;  
return 503;  
location @503 {  
root /;  
# Immediately serves 503 page, not $uri.  
# The fallback should never happen.  
try\_files /file/system/path/to/503.html =500;  
}  
…  
}

–  
O\< ascii ribbon campaign - stop html mail - [www.asciiribbon.org](http://www.asciiribbon.org)

---

<div class="post-metadata">

**Author:** ![Nginx\_U](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@Nginx\_U](https://www.ruby-forum.com/u/Nginx_U)\
**Post date:** [February 19, 2012, 6:56pm UTC](https://www.ruby-forum.com/t/error-page-return-bug/217006/23 "2012-02-19T18:56:53Z")

</div>

On 19 February 2012 20:34, Edho A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> root /;
> # Immediately serves 503 page, not $uri.
> # The fallback should never happen.
> try_files /file/system/path/to/503.html =500;
> 
> ```
> 
> }  
> …  
> }

I don’t think involving another domain/server to serve a single page  
is a particularly effective approach.

As mentioned, this serves the page as required along with the needed  
resources.

```
   error_page 503 /error_docs/custom503.html;
   if ( $request_uri !~ \.(jpg|gif|png|css|js)$ ) {
           set $tt "T";
   }
   if ( $request_uri !~ ^/maintenance/$ ) {
           set $tt "${tt}T";
   }
   if ( $tt = TT ) {
           rewrite ^ /maintenance/ redirect;
   }
   location /maintenance {
           internal;
           return 503;
   }
   location /error_docs {
           internal;
           alias /server/path/to/error_docs/folder;
   }

```

I have added it to a file 503.default which I just include (uncomment)  
in my normal server block

Server {  
include /server/path/to/503.default;  
…  
}

Nice and easy and all contained in one domain.  
Visitors are redirected to a “[example.com/maintenance/](http://example.com/maintenance/)” url which  
helps in passing info.

Works for me but as said, not the only possibility.

---

<div class="post-metadata">

**Author:** ![Nginx\_U](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@Nginx\_U](https://www.ruby-forum.com/u/Nginx_U)\
**Post date:** [February 19, 2012, 7:54pm UTC](https://www.ruby-forum.com/t/error-page-return-bug/217006/24 "2012-02-19T19:54:06Z")

</div>

On 19 February 2012 21:36, Edho A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Pretty sure will return 404 when accessing dynamic resources[1].  
> Hopefully you don’t have any or care about the impact.  
> No … because there is none as my maintenance page is a static page.  
> Only thing it uses is javascript which runs on client’s browser .

Anyway, not sure why this is dragging on.

I am perfectly happy with my setup. I don’t want to use a cdn for this  
page nor do I need to run a cgi script or similar on it.  
If you happen to use or prefer another setup, that’s fine with me as  
well.

Goodbye and thanks for your time.

---

<div class="post-metadata">

**Author:** ![Nginx\_U](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@Nginx\_U](https://www.ruby-forum.com/u/Nginx_U)\
**Post date:** [February 19, 2012, 7:37pm UTC](https://www.ruby-forum.com/t/error-page-return-bug/217006/25 "2012-02-19T19:37:20Z")

</div>

On Mon, Feb 20, 2012 at 12:56 AM, Nginx U. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I don’t think involving another domain/server to serve a single page  
> is a particularly effective approach.

Many larger sites use CDN for static contents. And the original config  
you wanted (if works) also do exactly that - returning 503 on all  
requests.

> As mentioned, this serves the page as required along with the needed resources.

Three ifs, two roundtrips on client. Looks much more inefficient to me  
😉

> I have added it to a file 503.default which I just include (uncomment)  
> in my normal server block

Or one if line:  
if ($uri ~ ^/error\_docs/) { return 503; }

No need to comment “error\_page …” and “location ^~ /error\_docs/” on  
normal operation.

> Works for me but as said, not the only possibility.

Pretty sure will return 404 when accessing dynamic resources[1].  
Hopefully you don’t have any or care about the impact.

[1] Images/resources served with rewrites, dynamic javascript/css, etc.

–  
O\< ascii ribbon campaign - stop html mail - [www.asciiribbon.org](http://www.asciiribbon.org)

[Previous page](https://www.ruby-forum.com/t/error-page-return-bug/217006.md?page=1)
