欢迎来到站长天空!

其它服务器

当前位置: 主页 > 服务器 > 其它服务器

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

时间:2025-12-07 13:30:02|栏目:其它服务器|点击:

一、简介

前端项目发布以后,经常会遇到访问不到最新的版本,这主要是由于我们项目的入口文件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=
Cache-control: s-maxage=

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不缓存的文章就介绍到这了,更多相关nginx html不缓存内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持! 

上一篇:tomcat部署jenkins项目的实现示例

栏    目:其它服务器

下一篇:nginx代理80端口不生效的解决方案

本文标题:nginx上设置html不缓存的方法实现

本文地址:https://zz.feitang.co/server/29152.html

广告投放 | 联系我们 | 版权申明

申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:257218569 | 邮箱:257218569@qq.com

Copyright © 2018-2025 站长天空 版权所有 Powered by EyouCms冀ICP备14023439号