nginx - NGINX 仅缓存特定目录中的图像、css、字体
问题描述
location ~* \.(js|css|png|jpg|jpeg|gif|svg|ico)$ {
expires 15d;
add_header Cache-Control "public, no-transform";
}
我有上面的代码,应该将这些文件缓存 15 天。如何修复它,以便仅缓存来自 /js、/css、/img 的文件而不是全部?
解决方案
将位置规则更改为:
location ~ ^/(js|css|img)/*\.(js|css|png|jpg|jpeg|gif|svg|ico)$ {
expires 15d;
add_header Cache-Control "public, no-transform";
}
那应该工作
推荐阅读
- reactjs - 调用 redux 操作的相应组件未捕获 Redux 响应
- elasticsearch - 使用弹性应用搜索实现基于标签的搜索
- c - 在我的情况下,C 语言中的“无符号”字是什么?
- laravel - 如何将以下查询转换为 Eloquent?
- swift - Swift 5.5:逐行异步迭代文件
- gmail - Gmail:帐户在发送时被禁用。您的消息未发送
- laravel - 如何使用 Laravel 7+ 在文件中记录 Guzzle Http 请求响应
- firebase - 我们有没有办法将角色设置为手动添加用户 firebase 控制台?
- elasticsearch - AWS ElasticSearch - Kibana 仪表板未加载
- java - Socket 无法连接到 ServerSocket 中指定的 IP 地址。(安卓工作室)