Bad side effect of (even unmatched) nested regex locations in regex locations with anonymous captures with try_files/alias

Maxim Dounin mdounin at
Thu Aug 2 10:42:49 UTC 2012


On Thu, Aug 02, 2012 at 10:38:15AM +0200, Christoph Schug wrote:

> Hello!
> I have another interesting scenario ;-) Given is following minimized
> test case

> server {
>     listen                          80;
>     server_name           ;
>     root                            /data/web/;
>     location                        ~ ^/bar(/.*)? {
>         alias /data/web/$1;

This is expected to break once between location matching and 
accessing a file (which will evaluate variables in the "alias" 
directive) any regexp matching will happen.

Not only nested regex location matching (which is kind of 
explicit), but even lookup of a map variable (with regexps) will 
be enough to break things.

And this is why it's not recommended to use enumerated captures 
except for very simple configurations (or "rewrite" directive, 
where use of enumerated captures immediatly follows regexp 
matching).  Use named captures instead and you'll be fine.


Maxim Dounin

More information about the nginx mailing list