I want to cache specific URLs in my application by directly looking at static files. However, statically cached files may not exist, so I only want to redirect the request if the files exist. I suppose I can use try_files somehow, but so far I have not been able to do this correctly.
Here is what I tried:
location ^/(.*)/(.*)/other/stuff/(.*)/this-is-static { try_files /static-cache/$1/$2/$3/this-is-static @app; }
static-cache is an internal location configured in the same file. This does not seem to work as intended. What's wrong?
The closest I got is that it overwrites each request (and thus it does not work when the file is not cached):
location ^/(.*)/(.*)/other/stuff/(.*)/this-is-static { rewrite ^ /static-cache/$1/$2/$3/this-is-static; }
source share