Py学习  »  NGINX

架构师成长记_第四周_05_Nginx使用Gzip压缩提升请求效率

流浪少年的梦 • 3 年前 • 137 次点击  

Nginx使用Gzip压缩提升请求效率

1. 打开nginx.conf文件进行配置

    # 开启gzip压缩功能, 目的: 提高静态资源的传输效率,节约带宽
    gzip  on;
    # 配置gzip
    
    # 限制最小压缩, 小于1字节文件不压缩
    gzip_min_length 1;

    
    # 设置压缩比, 压缩级别(1--9), 文件越大, 压缩越多, 但是cpu的使用会越多
    gzip_comp_level 3;

    # 设置压缩类型
    gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php imag
e/gif image/png application/json;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

在这里插入图片描述

测试配置并且重启nginx服务

nginx -t
nginx -s reload

对比结果

之前文件大小

在这里插入图片描述

使用Gzip后

在这里插入图片描述

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/110571
 
137 次点击