GZIP是网站压缩加速的一种技术,对于开启后可以加快我们网站的打开速度,原理是经过服务器压缩,客户端浏览器快速解压的原理,可以大大减少了网站的流量

Gzip配置参数

gzip on;  #是否开启gzip模块 on表示开启 off表示关闭
gzip_buffers 4 16k;  #设置压缩所需要的缓冲区大小
gzip_comp_level 6;  #压缩级别1-9,数字越大压缩的越好,也越占用CPU时间
gzip_min_length 100k;  #设置允许压缩的最小字节
gzip_http_version 1.1;  #设置压缩http协议的版本,默认是1.1
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;  #设置压缩的文件类型
gzip_vary on;  #加上http头信息Vary: Accept-Encoding给后端代理服务器识别是否启用 gzip 压缩

编辑配置文件

[root@linux /]# vim /usr/local/nginx/conf.d/www.conf
server {
  listen 80;
  server_name www.endvv.com endvv.com;
  root html/bk;
  index index.php index.html;
  access_log /usr/local/nginx/logs/www.log ;
  include /usr/local/nginx/php/www.conf;
  include /usr/local/nginx/wjt/typecho.conf;
  gzip on;
  gzip_buffers 4 16k;
  gzip_comp_level 6;
  gzip_vary on;
  gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
}

重载配置文件

/usr/local/nginx/sbin/nginx -s reload

检测Gzip是否开启

[root@linux /]# curl -I -H"Accept-Encoding: gzip, deflate" "https://www.endvv.com"
HTTP/1.1 200 OK
Date: Wed, 09 Sep 2020 11:03:15 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 14653
Connection: keep-alive
Server: NWS_SP
Cache-Control: max-age=600
Expires: Wed, 09 Sep 2020 11:13:14 GMT
Last-Modified: Wed, 09 Sep 2020 11:00:00 GMT
Content-Encoding: gzip
X-NWS-LOG-UUID: 14693dae-5256-44e6-8b18-005363d07159
X-Cache-Lookup: Hit From Disktank3 Gz
X-NWS-UUID-VERIFY: 236134fbce92c9f390484d544774b141
X-Pingback: https://www.endvv.com/action/xmlrpc

网页GZIP压缩检测

https://tool.chinaz.com/gzips/
请输入图片描述

Last modification:October 5th, 2020 at 05:01 am
如果觉得我的文章对你有用,请随意赞赏