Hello,
I’m trying to use try_files like this (running 0.7.34)
location /users/ {
root /home/website/people;
set $uroot 1/15/334251/fr.html;
try_files $document_root/$uroot @django;
}
Despite the fact that /home/website/people/1/15/334251/fr.html exists
and is readable by nginx, I’m always redirected to @django
This is an exemple, in real case the $uroot variable is build.
Here is the debug log :
2009/02/13 22:04:33 [debug] 14340#0: *1 try to use file: “/home/
website/people/1/15/334251/fr.html”
2009/02/13 22:04:33 [debug] 14340#0: *1 try to use file: “@django”
2009/02/13 22:04:33 [debug] 14340#0: *1 test location: “@django”
2009/02/13 22:04:33 [debug] 14340#0: *1 using location: @django “/
users/334251/fr/?”
Thanks in advance,
xav
On Fri, Feb 13, 2009 at 10:20:42PM +0100, Xavier G. wrote:
This is an exemple, in real case the $uroot variable is build.
Thanks in advance,
try_files tests files in relation to root, so:
- try_files $document_root/$uroot @django;
- try_files /$uroot @django;
On Fri, Feb 13, 2009 at 11:38:02PM +0100, Xavier G. wrote:
set $croot cache/$1/$1/$1/$2.html;
if I do set $croot like this (same value as before)
location /users/ {
set $croot cache/1/1/1/fr.html;
try_files $croot @django;
}
it works as expected. cache is served if exists or backend is called.
Where do I mixed up ?
This is because I unfortunately did not thoroughly think over “if”
blocks
inside nginx. Currently “if” block has it own configuration that
inherits
directives from previous level. The try_files is not inherited, so it
does not work inside “if”.
- try_files $document_root/$uroot @django;
- try_files /$uroot @django;
works well thanks for your answer.
finally the probleme is on the dynamic build of $croot for exemple :
location /users/ {
#set $croot cache/1/1/1/fr.html;
match /users/1/fr/xxxx/
if ($request_uri ~ /([0-9])/(\w+)/[-\w]+/$) {
set $croot cache/$1/$1/$1/$2.html;
set $deb 2;
}
sub_filter nginx ‘$croot - $uri - $deb’;
try_files $croot @django;
}
returns a 403 forbidden. wether the cache file exists or not.
With sub filter I can see that : nginx is well replace by ‘cache/1/1/1/
fr.html - /users/1/fr/xxxx/ - 2’ so all variables are set.
if I do set $croot like this (same value as before)
location /users/ {
set $croot cache/1/1/1/fr.html;
try_files $croot @django;
}
it works as expected. cache is served if exists or backend is called.
Where do I mixed up ?
thanks
xav
This is because I unfortunately did not thoroughly think over “if”
blocks
inside nginx. Currently “if” block has it own configuration that
inherits
directives from previous level. The try_files is not inherited, so it
does not work inside “if”.
Thanks your for your explaination. I did it the old fashion way. Nginx
is so flexible it makes us think everything is possible
xav