Combine several locations with regex in nginx
Posted
by
AlexAtNet
on Server Fault
See other posts from Server Fault
or by AlexAtNet
Published on 2012-03-22T19:34:43Z
Indexed on
2012/03/22
23:31 UTC
Read the original article
Hit count: 219
I dynamic number of Joomla installations in subfolders of the domain.
For example:
http://site/joomla_1/
http://site/joomla_2/
http://site/joomla_3/
...
Currently I have the follwing config that works:
index index.php;
location / {
index index.php index.html index.htm;
}
location /joomla_1/ {
try_files $uri $uri/ /joomla_1/index.php?q=$uri&$args;
}
location /joomla_2/ {
try_files $uri $uri/ /joomla_2/index.php?q=$uri&$args;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm/joomla.sock;
...
}
I'm trying to combine joomla_N rules in one:
location ~ ^/(joomla_[^/]+)/ {
try_files $uri $uri/ /$1/index.php?q=$uri&$args;
}
but server starts to return index.php as is (does not call the php-fpm).
It looks like the nginx stops the processing of the regex rules after the first match.
Is there any way to combine this rules with something like regex?
© Server Fault or respective owner