nginx上设置html不缓存的方法实现
更新时间:2024年02月29日 11:52:45 作者:花哥码天下
前端项目发布以后,经常会遇到访问不到最新的版本,这主要是由于我们项目的入口文件index.html被浏览器或者代理缓存了,本文主要介绍了nginx上设置html不缓存,具有一定的参考价值,感兴趣的可以了解一下
一、简介
前端项目发布以后,经常会遇到访问不到最新的版本,这主要是由于我们项目的入口文件index.html被浏览器或者代理缓存了,没有实时拉取到最新文件。本文将介绍一下在nginx上如何设置html文件不缓存。
二、Cache-Control介绍
2.1 服务器可以在响应中使用的标准 Cache-Control 指令。
Cache-control: must-revalidate Cache-control: no-cache Cache-control: no-store Cache-control: no-transform Cache-control: public Cache-control: private Cache-control: proxy-revalidate Cache-Control: max-age=<seconds> Cache-control: s-maxage=<seconds>
2.2 配置示例
2.2.1 禁止缓存
发送如下响应头可以关闭缓存。此外,可以参考Expires和Pragma消息头。
Cache-Control: no-store
三、nginx配置
location / {
expires 1h;
root /home/html;
index index.html index.htm;
## html不缓存
if ($request_filename ~* .*\.(htm|html)$)
{
add_header Cache-Control "no-store";
}
}
到此这篇关于nginx上设置html不缓存的文章就介绍到这了,更多相关nginx html不缓存内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
ConfigMap挂载与Subpath在Nginx容器中的应用小结
configmap可以通过ENV环境变量和文件两种方式挂载到容器中,修改configmap后容器中对应的ENV环境变量不会更新,将配置文件nginx.conf以configmap文件的方式挂载到容器中,本文介绍ConfigMap挂载与Subpath在Nginx容器中的应用小结,感兴趣的朋友一起看看吧2024-03-03
Nginx 配置 ModSecurity 网络应用防火墙实现
这篇文章主要介绍了Nginx 配置 ModSecurity 网络应用防火墙实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2023-12-12


最新评论