如何在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";
 }
}
相关推荐
hweiyu0012 小时前
Redis命令:HPERSIST
redis·缓存
hweiyu0012 小时前
Redis命令:HPEXPIRE
redis·缓存
starzy199015 小时前
Flink 优化之网络缓存优化及参数详解:从数据传输机制到反压原理的生产调优指南
网络·缓存·flink
ShineWinsu16 小时前
对于Redis:string类型的解析
java·c++·redis·分布式·缓存·面试·string
CoLiuRs18 小时前
电商价格是怎样算出来的
数据库·redis·缓存
蜗牛互联网1 天前
HSTU在Dynamo-Triton中的AOTI与KV缓存验收方法
java·人工智能·后端·缓存
hweiyu001 天前
Redis命令:HMGET
redis·缓存
陕西企来客2 天前
豆包检索层 9 月迭代后信源陈旧的核心 —— 缓存策略的可用性优先转向
缓存
三掌柜6662 天前
ArkWeb 手记 07|缓存和离线页怎么做
缓存·harmonyos
wefg13 天前
【Redis】初识 Redis
数据库·redis·缓存