Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想为静态 CSS 和 JavaScript 文件创建 NGINX 重写规则。
EG 浏览器请求:www.website.com/staticfiles/generatedhashhere/css/file.css
www.website.com/staticfiles/generatedhashhere/css/file.css
Nginx 应该注意:/staticfiles/css/file.css
/staticfiles/css/file.css
我想排除一个子目录路径。
是否可以使用 NGINX try_files 编写规则?
谢谢你的帮助!
我认为你让它变得比它需要的更复杂。与其使用 try_files 语句,不如简单地为 CSS 和 javascript 文件设置位置块,并为每个文件配置目录。
例子:
location ~* \.(css|js)$ { root /staticfiles/css/; }
如果您希望它是重写,则将根语句替换为
rewrite ^/staticfiles/generatedhashhere/css/(.*)$ /staticfiles/generatedhashhere/css/$;