我为 nginx 中的特定文件启用了缓存,如下所示:
location ~* \.(?:css|js)$ {
access_log off;
add_header Cache-Control "no-transform,public,max-age=31536000,s-max-age=31536000";
expires 1y;
}
Run Code Online (Sandbox Code Playgroud)
我想在这里做的是排除所有与模式 i18n-*.js 匹配的文件,因此,缓存除以 i18n 开头的文件之外的所有 .js 文件。
我尝试进行否定查找以排除该模式,但由于非捕获组,它无法正常工作:
location ~* \.(?!i18n-.*\.js)(?:css|js)$ {
access_log off;
add_header Cache-Control "no-transform,public,max-age=31536000,s-max-age=31536000";
expires 1y;
}
Run Code Online (Sandbox Code Playgroud)
这里的智能解决方案是什么?我不是正则表达式专家,所以简短的解释也会有帮助。