首页 > 其他 > 详细

nginx gzip压缩

时间:2015-07-20 16:54:45      阅读:265      评论:0      收藏:0      [点我收藏+]

确保已经安装ngx_http_gzip_module模块。

基本指令如下:

1.

Syntax(语法):gzip on | off;
               
Default(默认值):
gzip off;
               
content(应用场景):http, server, location

是否开启gzip模块  只有设置gzip为on时,才能使用该模块

2.

Syntax:gzip_buffers number size;
               
Default:
gzip_buffers 32 4k|16 8k;
               
Context:http, server, location

设置gzip压缩缓冲区大小 number:申请缓存空间的个数,size:每个缓存空间的大小

3.

Syntax:gzip_comp_level level;
               
Default:
gzip_comp_level 1;
               
Context:http, server, location

设置压缩级别,1~9,值越大,压缩程度越大,也就越费时

4.

Syntax:gzip_min_length length;
               
Default:
gzip_min_length 20;
               
Context:http, server, location

设置数据超过多大时才进行压缩,该长度可通过响应头Content-Length查看

5.

Syntax:gzip_http_version 1.0 | 1.1;
               
Default:
gzip_http_version 1.1;
               
Context:http, server, location

设置支持的http协议版本

6.

Syntax:gzip_types mime-type ...;
               
Default:
gzip_types text/html;
               
Context:http, server, location

设置mime类型,如text/html,text/css等  "*"表示任何类型

7.

Syntax:gzip_vary on | off;
               
Default:
gzip_vary off;
               
Context:http, server, location

响应头部是否展示“Vary: Accept-Encoding”

以下是配置参考:

gzip    on;
    gzip_min_length 1024;
    gzip_comp_level 2;
    gzip_http_version 1.1;
    gzip_types text/plain application/x-javascript text/css text/html application/xml;
    gzip_vary on;


更多说明,请查看官网http://nginx.org/en/docs/http/ngx_http_gzip_module.html

本文出自 “linux学习之路” 博客,请务必保留此出处http://raystudylinux.blog.51cto.com/9065684/1676301

nginx gzip压缩

原文:http://raystudylinux.blog.51cto.com/9065684/1676301

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!