Map module regular expression help

Hi,

In the wiki for the map module (Module ngx_http_map_module)
the
following is given as an example:

map $uri $myvalue {
/aa /mapped_aa;
~^/aa/(?.*)$ /mapped_bb/$suffix;
}

The second form, the regex, I can’t get to work - it returns the literal
text
rather than substituting for $suffix.

from my map block:

map $uri $locn {
~^/pdns(?.*)$ /var/www/pdns$suffix;
}

the I rewrite:

rewrite ^ $locn;

from the log:

open() “/var/www/pdns$suffix” failed

How do I get this to substitute?

This is using nginx/1.1.0 on debian squeeze.

Dick

On Fri, Aug 26, 2011 at 12:47:55PM +0100, Dick M. wrote:

rewrite ^ $locn;

from the log:

open() “/var/www/pdns$suffix” failed

How do I get this to substitute?

This is using nginx/1.1.0 on debian squeeze.

Wiki is wrong here. Currently nginx does not support expression
in value part, you may use only a single variable, i.e.:
~^/pdns(?.*)$ $suffix;

However, this wiki example is very ineffectual, because it maps $uri to
path
forcing to use “rewrite”. There are other simple ways to this, for
example:

location  /pdns {
    root  /var/www;
}

or (wiki expample):

location = /aa {
    alias  /mapped_aa;
}

location /aa/ {
    alias  /mapped_bb/;
}


Igor S.

On 08/26/11 13:02, Igor S. wrote:

On Fri, Aug 26, 2011 at 12:47:55PM +0100, Dick M. wrote:

Hi,

In the wiki for the map module (Module ngx_http_map_module) the
following is given as an example:

map $uri $myvalue {
/aa /mapped_aa;
~^/aa/(?.*)$ /mapped_bb/$suffix;
}

Wiki is wrong here. Currently nginx does not support expression
in value part, you may use only a single variable, i.e.:

I thought that might be it :wink:

What I’m trying to do is make my config file more elegant. I have quite
a
number of subdirectories which all have their own document root. So
there’s a
location for each and each has to have an alias and a php proxy. I was
trying
to coalesce them.

So I tried:

map $uri $locn {
/sub1 /locn1;
/sub2 /locn2;

 ...

}

index index.php;
location ~ ^/(sub1|sub2 etc ) {
alias $locn;

location ~ .php$ {

}
}

but it doesn’t work. fastcgi can’t find the file. One symptom is that
$request_filename is not set to the full path; i.e the index.php part is
missing.

It works OK if I put a literal in the alias rather than the same value
from a
mapped variable.

Is this construct supported?

There’s another problem I don’t understand

If I have

index index.php;

location /sub1 {
alias /path1;

}

It looks for /path1/index.php as expected but if I change location to
regex

location ~ ^/sub1

then it looks for /path1 with no index.

Dick