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=Cache-control: s-maxage=
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";
}
}

到此这篇关于nginx上设置html不缓存的文章就介绍到这了,更多相关nginx html不缓存内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
您可能感兴趣的文章
- 12-22nginx代理实现静态资源访问的示例代码
- 12-22Docker 存储管理的几种方式
- 12-22nginx静态资源的服务器配置方法
- 12-22Docker Compose部署微服务项目上线功能
- 12-22GPU服务器的多用户配置方法
- 12-22docker-compose搭建etcd集群的实现(三节点)
- 12-22docker中mysql开启日志的实现步骤
- 12-22Linux下docker安装mysql8并配置远程连接
- 12-22docker部署mysql8并设置可远程连接
- 12-22阿里云oss对象存储使用详细步骤


阅读排行
推荐教程
- 12-11docker存储目录迁移示例教程
- 12-10docker start启动容器后仍然exit状态的解决
- 12-10Linux下如何安装Logstash
- 12-19Zabbix SAML SSO 登录绕过漏洞的操作流程
- 12-15Docker-Compose搭建Spark集群的实现方法
- 12-14Docker Desktop无法正常启动解决(failed to start...)
- 12-14k8s 与docker空间使用分析与清理方法
- 12-13k8s编排之Deployment知识点详解
- 12-13Nginx IP封禁及自动封禁IP的实现
- 12-13Nginx代理Partainer如何使用





