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

相关推荐
java1234_小锋5 小时前
【技术专题】HTML5 网页技术 - HTML5简介 & HTML5 文档结构
前端·html·html5
wefg17 小时前
【Redis】安装与启动
数据库·redis·缓存
大圣编蚕7 小时前
常见的 Redis 面试题(高频整理)
数据库·redis·缓存
Coisinier8 小时前
docker命令管理镜像及容器
linux·运维·nginx·docker·容器·操作系统
2301_32241428049 小时前
基于web的校园失物招领管理系统59695-计算机毕设 原创(免费领源码+部署教程+开发环境)
mysql·nginx·php·apache·thinkphp·phpstudy·wampserver
梅菲塔亚9 小时前
博客_Redis入门到实战
数据库·redis·缓存
蓝胖的四次元口袋9 小时前
Redis 知识梳理(3)
数据库·redis·缓存
keyipatience10 小时前
JS学习笔记(2)数组,函数,作用域,对象
前端·javascript·笔记·学习·html
青春不朽51211 小时前
Python 里 a is b 有时 True 有时 False?小整数缓存和常量折叠的底层真相
python·spring·缓存
flytalei12 小时前
从YAML到Nginx服务访问:动手理解 Kubernetes Pod、Deployment 与 Service
运维·nginx·kubernetes