【发布时间】:2017-07-22 13:45:33
【问题描述】:
我为 nginx 中的特定文件启用了缓存,如下所示:
location ~* \.(?:css|js)$ {
access_log off;
add_header Cache-Control "no-transform,public,max-age=31536000,s-max-age=31536000";
expires 1y;
}
我想在这里做的是排除所有匹配模式 i18n-*.js 的文件,因此,缓存所有 .js 文件,除了以 i18n 开头的文件。
我尝试进行否定查找以排除该模式,但由于非捕获组,它无法正常工作:
location ~* \.(?!i18n-.*\.js)(?:css|js)$ {
access_log off;
add_header Cache-Control "no-transform,public,max-age=31536000,s-max-age=31536000";
expires 1y;
}
这里的智能解决方案是什么?我不是正则表达式专家,所以简短的解释也会有所帮助。
【问题讨论】:
标签: regex nginx browser-cache regex-lookarounds nginx-location