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

相关推荐
我命由我123455 小时前
UI 设计 7 种排列方式
xml·学习·ui·html·产品运营·产品经理·学习方法
Seraphina366 小时前
记一次实验:利用路径分隔符进行网页缓存欺骗
经验分享·笔记·安全·网络安全·缓存
xixingzhe28 小时前
nginx无网络升级
服务器·nginx
InfinitePlus9 小时前
redis数据持久化
数据库·redis·缓存
এ慕ོ冬℘゜9 小时前
深入理解浏览器全屏 API:从 requestFullscreen 到全屏实战
开发语言·html
weixin_4407305011 小时前
数据库缓存、索引、缓存命中率的理解
数据库·缓存
taocarts_bidfans15 小时前
Taoify 站点缓存分层配置实操,解决海外访问卡顿与更新延迟
缓存·外贸独立站·taoify
Demons_kirit16 小时前
PortSwigger网络缓存欺骗(3)
缓存
csuzhucong16 小时前
二十一 - 四十阶魔方
javascript·css·html
IMPYLH17 小时前
HTML 的 <main> 元素
前端·html