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

相关推荐
robch7 小时前
python3 -m http.server 8001直接启动web服务类似 nginx
前端·nginx·http
AscendKing8 小时前
免费、易用、覆盖全平台的网页转 PDF 工具
pdf·html·网页保存·网页保存为pdf·保存网页位pdf
cyber_两只龙宝9 小时前
【Nginx】Nginx实现FastCGI详解
linux·运维·nginx·云原生·php·memcached·fastcgi
BullSmall9 小时前
Prometheus 可以监控docker 部署的Nginx 吗?
nginx·docker·prometheus
刘~浪地球10 小时前
数据库与缓存--MySQL 高可用架构设计
数据库·mysql·缓存
魔卡少女110 小时前
Nginx配置代码化自动部署詹金斯/Github方案
前端·nginx·github
小兜全糖(xdqt)10 小时前
Ubuntu22.04安装最新版本redis
数据库·redis·缓存
ZC跨境爬虫11 小时前
海南大学交友平台登录页开发实战day4(解决python传输并读取登录信息的问题)
开发语言·前端·python·flask·html
倔强的胖蚂蚁11 小时前
AI 人工智能配置管理 Nginx
运维·nginx·云原生
邓霖涛12 小时前
nginx使用openSSL自签生成https相关证书
服务器·nginx·https