如何在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";
 }
}
相关推荐
在肯德基吃麻辣烫6 小时前
《Redis》缓存与分布式锁
redis·分布式·缓存
先睡12 小时前
Redis的缓存击穿和缓存雪崩
redis·spring·缓存
CodeWithMe1 天前
【Note】《深入理解Linux内核》 Chapter 15 :深入理解 Linux 页缓存
linux·spring·缓存
大春儿的试验田1 天前
高并发收藏功能设计:Redis异步同步与定时补偿机制详解
java·数据库·redis·学习·缓存
likeGhee1 天前
python缓存装饰器实现方案
开发语言·python·缓存
C182981825751 天前
OOM电商系统订单缓存泄漏,这是泄漏还是溢出
java·spring·缓存
西岭千秋雪_1 天前
Redis性能优化
数据库·redis·笔记·学习·缓存·性能优化
en-route1 天前
HTTP 缓存
网络协议·http·缓存
苦夏木禾2 天前
js请求避免缓存的三种方式
开发语言·javascript·缓存
重庆小透明2 天前
力扣刷题记录【1】146.LRU缓存
java·后端·学习·算法·leetcode·缓存