如何在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";
 }
}
相关推荐
啦啦啦_99993 小时前
Redis-2-queryFormat()方法
数据库·redis·缓存
forestsea5 小时前
深入理解Redisson RLocalCachedMap:本地缓存过期策略全解析
redis·缓存·redisson
啦啦啦_99997 小时前
Redis-0-业务逻辑
数据库·redis·缓存
自不量力的A同学7 小时前
Redisson 4.2.0 发布,官方推荐的 Redis 客户端
数据库·redis·缓存
fengxin_rou8 小时前
[Redis从零到精通|第四篇]:缓存穿透、雪崩、击穿
java·redis·缓存·mybatis·idea·多线程
fengxin_rou8 小时前
黑马点评实战篇|第二篇:商户查询缓存
缓存
笨蛋不要掉眼泪9 小时前
Redis哨兵机制全解析:原理、配置与实战故障转移演示
java·数据库·redis·缓存·bootstrap
ALex_zry21 小时前
Redis Cluster 分布式缓存架构设计与实践
redis·分布式·缓存
shuair1 天前
redis缓存预热、缓存击穿、缓存穿透、缓存雪崩
redis·spring·缓存
上架ipa1 天前
redis图形化客户端功能对比
redis·缓存