if-clause garbles variable content

marius nginx-forum at nginx.us
Sun Dec 20 09:22:01 MSK 2009

Maxim Dounin Wrote:

> This is somewhat expected, as you trashed captures
> from location by executing another regex.
> You should either use named captures as supported
> in nginx 0.8.25+, like this:
>     location ~* ^/aabbccddeeff(?/.*) {
>         ...
>         alias /tmp/test/aabbccddeeff$file;
>     }

Now that you're mentioning the captures, it all makes sense.
I'd consider this a last resort solution, as running the current stable build is definitely a plus.

> or save capture results before executing another
> regexp, e.g.
>     location ~* ^/aabbccddeeff(/.*) {
>         set $file $1;
>         ...
>         alias /tmp/test/aabbccddeeff$file;
>     }

I already tried that way, but the configuration doesn't validate:
the "alias" directive must use captures inside location given by regular expression in

> And this one isn't expected, but seems to be just another chapter 
> in "if is evil" saga.  In this particular case alias directive 
> isn't correctly inherited into implicit location created by if(), 
> and this screws things up.

For legacy reasons, the first directory could be all uppercase or all lowsercase. Avoiding the initial capture through $uri does the job.

Thank you for your help.

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,31950,32045#msg-32045

More information about the nginx mailing list