本文主要是介绍Nginx 配置Gzip提升加载速度,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
前言:
加载显示速度过慢,设置gzip可以提升加载速度。
新建 gizp.conf
#开启gzip压缩
gzip on;
#设置允许压缩的页面最小字节数
gzip_min_length 1k;
#申请4个单位为16K的内存作为压缩结果流缓存
gzip_buffers 4 16k;
#设置识别http协议的版本,默认为1.1
gzip_http_version 1.1;
#指定gzip压缩比,1-9数字越小,压缩比越小,速度越快
gzip_comp_level 2;
#指定压缩的类型
gzip_types text/plain application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
#让前端的缓存服务器进过gzip压缩的页面
gzip_vary on;
#IE6对Gzip不怎么友好,不给它Gzip了
gzip_disable "MSIE [1-6]\.";
导入 nginx.onf
http {include mime.types;default_type application/octet-stream;#开启高效文件传输模式sendfile on;#设置客户端连接保存活动的超时时间keepalive_timeout 65;#压缩配置include gizp.conf;#导入项目网站include vhosts/*.conf;
}
重启Nginx服务
nginx -s reload
用curl测试Gzip是否成功开启
[root@itstyle nginx]# curl -I -H "Accept-Encoding: gzip, deflate" "http://www.dhing.com/data/cache/common.js"
HTTP/1.1 200 OK
Server: nginx/1.10.3
Date: Mon, 05 Feb 2018 01:49:24 GMT
Content-Type: application/javascript
Last-Modified: Wed, 13 Dec 2017 07:45:08 GMT
Connection: keep-alive
ETag: W/"5a30da84-d95d"
Content-Encoding: gzip
简单实用~~
这篇关于Nginx 配置Gzip提升加载速度的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!