Welcome! Log In Create A New Profile

Advanced

Using 'set' values in 'location'?

January 28, 2011 05:10PM
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':

1) Can I use variables I create with 'set' in 'location' as regular strings? Such as:

[code]
server {
set $subdir "/somesubdir";

location $subdir/ {
try_files $uri $uri/ $subdir/index.php;
}
}
[/code]


2) Can I use variables I create with 'set' in 'location' regular expressions? Such as:

[code]
server {
set $subdir "/somesubdir";

location ~ ^$subdir(.*/)?anotherdir/$ {
rewrite ^ $subdir/index.php last;
}
}
[/code]


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
Subject Author Posted

Using 'set' values in 'location'?

JackHebron January 28, 2011 05:10PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 281
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