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

相关推荐
回忆2012初秋7 小时前
【Nginx】原理、配置与运维实战(2)
运维·nginx·策略模式
阿豪啊12 小时前
记一次 Nginx 跨域配置踩坑与优化:从嵌套 If 报错到 Map 指令最佳实践
nginx
AOwhisky12 小时前
Redis 学习笔记(第四期):高可用与集群(哨兵 + Cluster + 容器化)
linux·运维·数据库·redis·笔记·学习·缓存
MXsoft61814 小时前
**断网续传与本地缓存:弱网环境下的监控数据保障方案**
运维·缓存·自动化
xingyuzhisuan14 小时前
缓存命中率提升方案:从 30% 优化至 82% 全流程优化记录
java·开发语言·缓存·ai
Konwledging14 小时前
Cache Incoherent(缓存不一致)
缓存
慕木沐16 小时前
【Spring AI + Google ADK 】流式输出时 outputKey 状态缓存失败的问题
人工智能·spring·缓存
jnene16 小时前
html 时间、价格筛选样式处理
前端·css·html
swordbob16 小时前
缓存延迟双删的两种策略
java·缓存
slongzhang_16 小时前
jquery 修复怪异模式html未声明“<!DOCTYPE html>”
前端·html·jquery