Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Having a file on /GET-cache/contact.html and requesting the URI /contact, with this directive, it works as expected:

if (-f $document_root/$request_method-cache$uri.html) {
  rewrite (.*) /GET-cache/$1.html break;
}

This one doesn't:

try_files $request_method-cache$uri.html @backend;

Using $document_root in the try_files directive doesn't work either (what I mean when I say it doesn't work is that the request gets passed up to the backend instead of nginx serving the static file).

Am I missing something?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

I think this is just a matter of not starting your check with a forward slash. Try this:

try_files /$request_method-cache$uri.html @backend;

Nginx applies each argument to try_files to the root directive. So if your root is /var/www then it'll check against var/wwwGET-cache/foo.html

share|improve this answer
    
That was quick, thanks a lot! –  Ivan Jun 29 '11 at 20:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.