I’m still working on getting nginx installed but I want to get a head
start on the configuration. I have a couple questions regarding ‘set’:
- Can I use variables I create with ‘set’ in ‘location’ as regular
strings? Such as:
server {
set $subdir "/somesubdir";
location $subdir/ {
try_files $uri $uri/ $subdir/index.php;
}
}
- Can I use variables I create with ‘set’ in ‘location’ regular
expressions? Such as:
server {
set $subdir "/somesubdir";
location ~ ^$subdir(.*/)?anotherdir/$ {
rewrite ^ $subdir/index.php last;
}
}
I recognize that probably isn’t correct syntax for the regular
expression portion since $ indicates ‘match end of string’, but my goal
here should be clear.
Also open to alternative solutions. I am aware that “if is evil” and
I’ve read the “pitfalls” wiki documentation, so I was trying to avoid
using ‘if’ and try to use ‘location’ and ‘rewrite’/‘try_files’
exclusively. I also don’t have access to a working nginx server yet or
I’d probably just test it myself.
–
Jack
Posted at Nginx Forum: