Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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


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.