nginx 配置 gzip压缩及去除 html 缓存

python 复制代码
server{
  listen       80;
  server_name  test.exmaple.cn;
  
  gzip on; # 是否开启gzip
  # gzip_buffers 32 4K; # 缓冲(压缩在内存中缓冲几块? 每块多大?)
  gzip_comp_level 6; # 推荐6 压缩级别(级别越高,压的越小,越浪费CPU计算资源)
  gzip_min_length 1k; # 开始压缩的最小长度(再小就不要压缩了,意义不在)
  gzip_types text/plain application/javascript text/css text/xml; # 对哪些类型的文件用压缩 如txt,xml,html ,css
  gzip_disable "MSIE [1-6]\."; #正则匹配UA,配置禁用gzip条件。此处表示ie6及以下不启用gzip(因为ie低版本不支持)
  # gzip_http_version 1.1; # 开始压缩的http协议版本(可以不设置,目前几乎全是1.1协议)
  gzip_vary on; # 是否传输gzip压缩标志

  location / {
      if ($request_filename ~* .*\.(?:htm|html)$)  ## 配置页面不缓存html和htm结尾的文件
       {
          add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
       }
       root /web/;
       index index.html;
       try_files $uri $uri/ /index.html =404;
   }
}

参考来源:

https://juejin.cn/post/6982757068587565064

https://blog.csdn.net/GX_1_11_real/article/details/118489967

相关推荐
吴声子夜歌1 小时前
Redis 6.x——监控指标
数据库·redis·缓存
heimeiyingwang14 小时前
【架构实战】缓存一致性:Cache Aside与双写问题的破解
spring·缓存·架构
悦儿遥遥雨115 小时前
PXE + Kickstart 无人值守批量部署系统
linux·javascript·nginx
大E帝国子民120 小时前
OpenCloudOS Server 9 安装 Nginx 完整指南
前端·网络·nginx
青山木1 天前
Redis 高可用的最后一公里:Cluster 分片、Gossip 与故障转移全流程
数据库·redis·后端·缓存
iCOD3R1 天前
【趣站精选】2026-07-13
开源·html
H Journey1 天前
web开发学习:html、css、js
前端·css·html·js
952361 天前
Redis - 基本操作
数据库·redis·spring·缓存
今日无bug1 天前
Emmet 语法速成指南
前端·css·html
kisshyshy1 天前
前端存储、表单异步提交与 this 指向完全指南
前端·javascript·html