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

相关推荐
热爱Java,热爱生活12 分钟前
浅谈Spring三级缓存
java·spring·缓存
heRs BART24 分钟前
Redis简介、常用命令及优化
数据库·redis·缓存
蒸汽求职44 分钟前
破局“无效互面”:跨国大厂视角的工业级 Mock Interview 价值解析
缓存·面试·职场和发展·金融·notion
Irissgwe2 小时前
redis之常见数据类型
数据库·redis·缓存
七七powerful2 小时前
loki监控docker容器&系统&nginx日志的告警规则
nginx·docker·容器
DROm RAPS2 小时前
redis 配置
数据库·redis·缓存
赵庆明老师4 小时前
vben开发入门5:vite.config.ts
前端·html·vue3·vben
SeSs IZED4 小时前
Redis开启远程连接
数据库·redis·缓存
dovens6 小时前
httpslocalhostindex 配置的nginx,一刷新就报404了
运维·nginx
yqcoder6 小时前
uni-app 数据缓存详解
缓存·uni-app