"error_page"& "return" bug?

Nginx User nginx at nginxuser.net
Sun Feb 19 17:56:14 UTC 2012


On 19 February 2012 20:34, Edho Arief <edho at myconan.net> wrote:
> 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;
>       }
>       ...
> }

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/" url which
helps in passing info.

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



More information about the nginx mailing list