Using map module variable being unset with if

Maxim Dounin mdounin at mdounin.ru
Wed Jun 22 12:48:21 MSD 2011


Hello!

On Wed, Jun 22, 2011 at 01:06:20AM -0400, kamlou wrote:

> Hey guys,
> 
> I have been trying to use the nginx map module to do some rewrites in
> bulk, basically my
> map looks something like this:
> 
> map $request_body $var {
>  default no;
>  ~.+.string1 dorw;
>  ~.+.string2 dorw;
>  ...
> }
> 
> in a location i have the following
> 
> if ($var = dorw){
>  rewrite ^ /home last;
> }
> 
> I also have a log_format which logs the variable state (and it reports
> correct), however
> once I enable that if.. the $var seems to reset to 'no'.
> 
> Any ideas? This is kind of confusing.

$request_body isn't available unless it's read, and this happens 
after rewrite phase where "if" is executed.  Therefore testing 
$var with "if" will always result in "no" and this result will be 
cached for further use.

Maxim Dounin



More information about the nginx mailing list