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

相关推荐
就叫飞六吧7 分钟前
DeepSeek Harness 本地安装与启动指南
nginx
難釋懷5 小时前
Nginx主动健康检查
运维·nginx
zh_xuan6 小时前
github搭建个人主页
html·github
NeilYuen8 小时前
【vemory】高性能KV存储AOF方案设计
linux·c++·redis·缓存
小妖6669 小时前
设置了 box-sizing: border-box; 不管用,下边框还是被挤压没了
前端·css·html
LuminousCPP9 小时前
数据结构基础篇(二):顺序表与链表全方位对比|从内存布局到 CPU 缓存理解底层差异
c语言·数据结构·经验分享·链表·缓存
spter。9 小时前
Redis 与 Single-flight 的分工与协作
数据库·redis·缓存
清水白石00812 小时前
Python 如何设计一个线程安全的缓存?从锁策略、LRU 到工程化实战
python·安全·缓存
難釋懷12 小时前
Nginx-Openresty
nginx·junit·openresty
qetfw12 小时前
Debian 部署 Discuz! 论坛:Nginx、PHP 与 MariaDB 配置
linux·运维·nginx·debian·php·discuz