当前位置: 代码网 > 服务器>服务器>Nginx > nginx上设置html不缓存的方法实现

nginx上设置html不缓存的方法实现

2024年05月18日 Nginx 我要评论
一、简介前端项目发布以后,经常会遇到访问不到最新的版本,这主要是由于我们项目的入口文件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 禁止缓存

发送如下响应头可以关闭缓存。此外,可以参考expirespragma消息头。

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不缓存内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网! 

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com