error_page can not work in if directive

Maxim Dounin mdounin at mdounin.ru
Tue Dec 25 15:27:01 UTC 2012


Hello!

On Tue, Dec 25, 2012 at 10:09:45AM -0500, xinghua_hi wrote:

> thank you very much, but i sitll  want to know why error_page can't work
> normally in if block.
> I see the error_page 's context can be " if in location" in the document.
> 
> the whole location conf  like below, error_page can not work:
> 
>  client_max_body_size 50k;
>   location / {
>             set $var "haha";
>             if ($var = "haha") {
>                 error_page 413 /413.html;
>             }
>         }
> 
> but 
> 
> client_max_body_size 50k;
>   location / {
>              error_page 413 /413.html;
>         }
> it works!

The 413 error is generated once location configuration is 
determinded, and this happens before location-level rewrite module 
directives (the "if" directive in particular) are executed.  Hence 
error_page 413 configure inside the "if" doesn't make any 
difference.

(Please also note that in general it's a good idea to avoid using 
the "if" directive, see http://wiki.nginx.org/IfIsEvil.)

-- 
Maxim Dounin
http://nginx.com/support.html



More information about the nginx mailing list