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

相关推荐
PieroPc2 天前
一个功能强大的 Web 端标签设计和打印工具,支持服务器端直接打印到局域网打印机。Fastapi + html
前端·html·fastapi
海的透彻2 天前
nginx启动进程对文件的权限掌控
运维·chrome·nginx
mameng19982 天前
Redis遇到热点key如何解决
数据库·redis·缓存
小红的布丁2 天前
Redis 持久化详解:AOF、RDB 与混合持久化如何平衡性能和可靠性
数据库·redis·缓存
一个有温度的技术博主2 天前
Redis Cluster 核心原理:哈希槽与数据路由实战
redis·算法·缓存·哈希算法
周末也要写八哥2 天前
追求性能极致为何不用Redis?
数据库·redis·缓存
my_styles2 天前
linux系统下安装 tengine / 宝兰德等国产信创中间件和闭坑
linux·运维·服务器·spring boot·nginx·中间件
一个有温度的技术博主2 天前
Redis集群实战:如何实现节点的弹性伸缩与数据迁移?
redis·分布式·缓存·架构
Jul1en_2 天前
【Redis】常用命令及定时器实现思想
数据库·redis·缓存
杰克尼2 天前
redis(day02-短信登录)
数据库·redis·缓存