53 Nginx中Gzip压缩功能的实例配置

53 Nginx中Gzip压缩功能的实例配置

53.1 Gzip压缩功能的实例配置

将涉及压缩的参数抽取到一个配置文件中,通过 include 指令将配置文件再次加载到 nginx.conf 配置文件中

[root@nginx-100 /usr/local/nginx/conf]# cat nginx_gzip.conf 
gzip on;           # 开启gzip压缩功能
gzip_types *;      # 压缩源文件类型,根据具体的访问资源类型设定
gzip_comp_level 6; # gzip压缩级别
gzip_min_length 1024;   # 进行压缩响应页面的最小长度, content-length
gzip_buffers 4 16k;     # 缓存空间大小
gzip_http_version 1.1;  # 指定压缩响应所需要的最低HTTP请求版本
gzip_vary on;           # 往头信息中添加压缩标识
gzip_disable "MSIE [1-6]\.";  # 对IE6 以下的版本都不进行压缩
gzip_proxied off;             # nginx作为反向代理压缩服务端返回数据的条件

 

[root@nginx-100 /usr/local/nginx/conf]# cat nginx.conf
..........
http {
..........
    include nginx_gzip.conf;
..........
    }  
}
[root@nginx-100 /usr/local/nginx/conf]# nginx -t && nginx -s reload
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

 

———————————————————————————————————————————————————————————————————————————

                                                                                                                         无敌小马爱学习

posted on 2026-05-14 17:44  马俊南  阅读(2)  评论(0)    收藏  举报