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?
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 againstvar/wwwGET-cache/foo.html