location /image_mini { # try_files /static_images/$2.jpg; rewrite ^/image_mini/([^.]+)-00([0-9]+)\.jpg$ /image.php?a=$2 last; } I use this rewrite rule to display images on my website. For example, if I want to display Image ID #123456789, I would use https://www.example.com/image_mini/some_cool_seo_keywords-00123456789.jpg
Then, image.php will check if /static_images/00123456789.jpg is found in local cache, if not it will create the file.
I assume I would get much better performance if nginx could look for the local static file before fallback to image.php
I tried doing this with try_files but I am unsure how to extract the image ID from the URL and i'm stuck here :( Any help would be appreciated