error_page can not work in if directive

Maxim Dounin mdounin at mdounin.ru
Tue Dec 25 17:24:01 UTC 2012


Hello!

On Tue, Dec 25, 2012 at 11:47:58AM -0500, xinghua_hi wrote:

> thanks, but a new question comming。
> I try to resolve my problem according to your method:
> (1)
> “set" is also an location-level rewrite module directive, so the conf like
> this 
>  location / {
>            root XXX;
>             set $var "haha";
>             error_page 413 /413.${var}.html;
>         }
> 
> will return 404, but 413.haha.html  exists my root dir。I see the debug log ,
> find some log like 
>         http finalize request: 404, "/413..html?"
> obviously, nginx  takes $var as an empty string, I  think the reason is also
> that 413 error is generated  before set directive? so , how to use variable
> in error_page uri? 

Same problem here: the "set" directive isn't executed, and hence 
the $var isn't "haha" but uninitialized and evaluates to an empty 
string.

You have to make $var variable available by other means (e.g. set 
the variable at server level, or make it available via map{} 
directive).

> (2)
> if  I  writer conf  like this:
> location / {
>       set $var "haha";
>        error_page 413  /413.html;
> }
> 
> location = /413.html {
>       if ($var)  {
>            rewriter ^  /413.new.html;
>      }
> }
> 
> the key problem is   how can i  pass the $var to location /413.html?  I try
> it , the second $var is empty(I also wonder about the result because I
> remember when internal redirect,  the location can share the variable) 。

And the same problem here: "set $var "haha";" in the location / 
isn't executed, and hence $var remains uninitialized.

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



More information about the nginx mailing list