Using 'set' values in 'location'?

JackHebron nginx-forum at nginx.us
Sat Jan 29 01:10:54 MSK 2011


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

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,170551,170551#msg-170551




More information about the nginx mailing list