Correct NGINX rewrite rule for static files Correct NGINX rewrite rule for static files nginx nginx

Correct NGINX rewrite rule for static files


I think you are making it more complex than it needs to be. Instead of using a try_files statement for this, it would be easier to simply set up location blocks for CSS and javascript files with the directory configured for each one.

Example:

location ~* \.(css|js)$ {root /staticfiles/css/;}

If you want it to be a rewrite, then replace root statement with

rewrite ^/staticfiles/generatedhashhere/css/(.*)$ /staticfiles/generatedhashhere/css/$;