Location regexp with multiple Wordpress install

Hello,

I have a problem with my location rules.
I would like to generate a generic location rule for each folder that
contains a WordPress installation.

location / {
try_files $uri $uri/ /index.html;
}

location /user1/ {
try_files $uri $uri/ /user1/index.php?q=$uri&$args;
}

location ~* ^/(user2|user3)/ {
try_files $uri $uri/ /$1/index.php?q=$uri&$args;
}

location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}

If I go to localhost/user1/, I am redirected to the good Wordpress. But,
if I go to localhost/user2/ my browser downloads a file containing the
source code of index.php.
How to get it working?

Thank you.

Posted at Nginx Forum:

On Wed, Jun 01, 2011 at 05:59:30AM -0400, Amanager wrote:

location /user1/ {
include fastcgi_params;
}

If I go to localhost/user1/, I am redirected to the good Wordpress. But,
if I go to localhost/user2/ my browser downloads a file containing the
source code of index.php.
How to get it working?

This is why I do not like regex locations - you have always to watch
over order of these locations. In this case you should place
“location ~ .php$” before “location ~* ^/(user2|user3)/”.
You will use only usual locations, you can place it in any order.


Igor S.

Thank you very much Igor.
It works.

Posted at Nginx Forum: