How can I write a location block that matches any path ending in the following extensions:
jpg|jpeg|gif|css|png|js|ico|json|xml|txt|html
Unless the path starts with "/rails" (eg: /rails/randomstring/image.png)?
I currently have this basic block:
location ~* \.(jpg|jpeg|gif|css|png|js|ico|json|xml|txt|html)$ {
gzip_static on;
gzip on;
expires max;
add_header Cache-Control public;
}
But this would match "/rails/randomstring/image.png" and I don't want that.
You can anchor a negative lookahead to the beginning of the string:
^(?!\/rails).*(?:jpg|jpeg|gif|css|png|js|ico|json|xml|txt|html)
Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With