I need to create a virtual sub directory in nginx which will serve files from a different location than the root. This virtual directory also runs PHP, but I've omitted the fastcgi config for brevity.
I have two location blocks, the one for the /virtual directory uses alias, while the location block for / has it's own root directive. This root directive gets inherited by the virtual folder, messing up the paths. Is there any way I can exclude urls in /virtual from inheriting the root directive of the / location block?
Here is an excerpt of my server config:
server {
root /path/to;
location ^~ /virtual/ {
alias /path/to/lions/public;
try_files $uri $uri/ /lions/public/index.php?$query_string;
}
location / {
root /path/to/tigers/public;
try_files $uri $uri/ /index.php?$query_string;
}
}
If I browse to hostname/virtual/whatever, nginx looks for the file at
/path/to/tigers/public/lions/public/whatever
instead of
/path/to/lions/public/whatever
I have tried the following pattern to match all urls at / except for those starting with /virtual, but that didn't match anything.
location ^~ ((?!\/virtual)\/.*)$
I have also tried putting both an alias and a root directive in the location block for /virtual, but nginx wouldn't start.
Is there any other way to have a different root for my alias directory?