"error_page"& "return" bug?

Nginx User nginx at nginxuser.net
Sun Feb 19 12:59:36 UTC 2012


On 19 February 2012 15:45, Nginx User <nginx at nginxuser.net> wrote:
> On 19 February 2012 15:03, Maxim Dounin <mdounin at mdounin.ru> wrote:
>> Another possible aproach is to use named location in error_page.
>> It won't re-execute server rewrites (that is, rewrite module
>> directives, including the "return" directive, specified at server
>> level) and will work as well.
>
> Unfortunately, this doesn't appear to work as expected either
>
> Server {
>       # listen etc
>       ...
>
>       error_page 503 = @sitedown;
>       return 503
>       location @sitedown {
>               root /server/path/to/folder;
>               # Don't you wish try_files could accept a single parameter?
>               try_files $uri /custom503.html;
>       }
>
>       ...
> }

PS.

In any case, it would not be an ideal solution even if it did work as
it would return a "200" status code with the custom file.

So getting things to work as with the location option is probably best.

In the interim, I have managed to get it to work by first redirecting
to a location and issuing the 503 status code there

Server {
	error_page 503 /error_docs/custom503.html;
	rewrite ^ /sitedown/ redirect;
	location /sitedown {
		return 503
	}
	location /error_docs {
		internal;
		 alias /server/path/to/error_docs/folder;
	}
}



More information about the nginx mailing list