I’m on Nginx 0.8.54 trying to achieve the following as DRYly as possible:
- Proxy straight to
localhost:8060if cookieno_cacheistrueor if request method isn’tGET. - Otherwise serve static files from
$document_root/static/$uri. - If no such file exists, try
$document_root/cache/$uriand$document_root/cache/$uri.html. - If the request path is
/, try no static files and only$document_root/cache/index.html. - Finally fall back to
localhost:8060if neither static nor cached files are found.
Current configuration file:
server {
root /srv/web/example.com;
server_name example.com;
location @backend { proxy_pass http://localhost:8060; }
location / {
if ($cookie_no_cache = true) { proxy_pass http://localhost:8060; }
if ($request_method != GET) { proxy_pass http://localhost:8060; }
try_files /static/$uri /cache/$uri /cache/$uri.html @backend;
}
location = / {
if ($cookie_no_cache = true) { proxy_pass http://localhost:8060; }
if ($request_method != GET) { proxy_pass http://localhost:8060; }
try_files /cache/index.html @backend;
}
}