注册 X
提交 注:点击提交后系统会发送邮件到邮箱验证!(仅支持中国大陆邮箱)
我已阅读并同意 服务条款
首页 > IT技术笔记 > 查看笔记

Nginx开启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.wouuz.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			
	      

 打赏        分享



评论

邮箱: 昵称:
\n