Welcome! Log In Create A New Profile

Advanced

Using variables in location directive

Posted by yz 
yz
Using variables in location directive
December 28, 2011 08:34AM
I've got several virtual hosts ("server {...}") with the same regexp in `location' directive, but different actions for. E.g.:
server {
server_name first_name.com
...
location ~* ^.+\.(zip|tar|gz|bz2)$ {
root /var/www/first_name.com/archives/
}
...
}

server {
server_name second_name.com
...
location ~* ^.+\.(zip|tar|gz|bz2)$ {
try_files /arch/storage/$uri /arch/another_storage/$uri =404;
}
...
}

When I need to adjust this regexp ("^.+\.(zip|tar|gz|bz2)$"), I have to edit each virtual host in turn. Is there any possibility to use variable in `location'? E.g.:
server {
...
set $regexp "(zip|tar|gz|bz2)";
location ~* ^.+\.${regexp}$ {
root /var/www/first_name.com/archives/
}
...
}

Then I'd just `include' common setting for each virtual host.
Or is there any other way to do something like that?

yz-ripe
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 195
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready