"error_page"& "return" bug?

Maxim Dounin mdounin at mdounin.ru
Sun Feb 19 12:03:18 UTC 2012


Hello!

On Sun, Feb 19, 2012 at 01:22:34PM +0300, Nginx User wrote:

> Hello,
> 
> It appears that the error_page directive is ignored when a status code
> is returned  in the server context. (running v1.0.12 Stable).
> 
> Server {
> 	# listen etc
> 	...
> 	
> 	error_page 503 /error_docs/custom503.html;
> 	return 503
> 	location /error_docs {
> 		internal;
> 		alias /server/path/to/folder;
> 	}
> 	
> 	...
> }
> 
> Will always return the Nginx default 503 page. Same applies to all status codes.

It's not ignored, but returning error unconditionally in the 
server context also prevents error_page processing from 
working, as the "return 503" is again executed after error_page 
internal redirect.  That is, something like this happens:

1. Request comes for "/something".
2. Server rewrites generate 503.
3. Due to error_page set the request is internally redirected to 
   /error_docs/custom503.html.
4. Server rewrites again generate 503.
5. As we've already did error_page redirection, nginx ignores 
   error_page set and returns internal error page.

> When the status code is returned within a location block, the custom
> page is shown as expected ...
> 
> Server {
> 	# listen etc
> 	...
> 	
> 	error_page 503 /error_docs/custom503.html;
> 	location / {
> 		return 503;
> 	}
> 	location /error_docs {
> 		internal;
> 		alias /server/path/to/folder;
> 	}
> 	
> 	...
> }

This doesn't "return 503" for error_page processing, and hence it 
works ok.

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. 

Maxim Dounin



More information about the nginx mailing list