E
E
ex0rcist2014-06-26 14:16:07
Nginx
ex0rcist, 2014-06-26 14:16:07

Nginx, try_files - why doesn't it work?

We have this config -

set $static_root /home/....
set $folder ...

location @vincent {
  proxy_pass http://vincent;
}

location ~* "/img/([a-z0-9\-]{2,5})/([a-z]{1,3})/([0-9]{1,2}\.jpg)" {

  set $cache $static_root/cached/$folder/$1/$2/$3;
  set $cache_common $static_root/cached/common/$1/$2/$3;


  try_files $cache $cache_common @vincent;

  #if (-f $cache) {
  #    return 301; break;
  #
}

We get a fallback on @vincent, although the cached file exists, and the uncommented IF gives us a 301 page. What have I done wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
neol, 2014-06-26
@neol

try_files does not accept absolute paths, always appending the contents of $document_root before the string passed. So you need to set the normal value of the root.
You get something like:

location ~* "/img/([a-z0-9\-]{2,5})/([a-z]{1,3})/([0-9]{1,2}\.jpg)" {
  root /;
  set $cache $static_root/cached/$folder/$1/$2/$3;
  set $cache_common $static_root/cached/common/$1/$2/$3;
  try_files $cache $cache_common @vincent;
}

But something like this is better:
location ~* "/img/([a-z0-9\-]{2,5})/([a-z]{1,3})/([0-9]{1,2}\.jpg)" {
  root $static_root;
  set $cache /cached/$folder/$1/$2/$3;
  set $cache_common /cached/common/$1/$2/$3;
  try_files $cache $cache_common @vincent;
}

G
Grag, 2014-06-26
@Grag

Sori that offtopic, you can throw off an example of a human config with ssl, otherwise I'm tired of asking here, no one answers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question