ngx_http_gzip_module
ngx_http_gzip_module
用gzip方法压缩响应数据,节约带宽
gzip on | off;
启用或禁用gzip压缩
Default: gzip off;
Context: http, server, location, if in location
gzip_comp_level level;消耗CPU
压缩比由低到高:1 到 9, 默认:1
gzip_disable regex ...;
匹配到客户端浏览器不执行压缩
示例:gzip_disable "MSIE[1-6]\."; 老IE不支持压缩
gzip_min_length length;
启用压缩功能的响应报文大小阈值
示例:
[[email protected] conf.d]# vi /apps/nginx4/conf/conf.d/test.conf server { server_name www.magedu.org; root /data/site14/; access_log /apps/nginx4/logs/magedu.org.access.log access_json ; default_type text/html ; gzip on; #启用压缩 gzip_comp_level 6; #压缩级别 gzip_min_length 64; #超过64字节压缩 gzip_vary on; #在响应头加入压缩提示 gzip_types text/xml text/css application/javascript; #指定压缩的文件类型 }
验证结果:
没启用压缩前测试:
[[email protected] conf.d]# curl -I www.magedu.org/messages #复制到根资源目录下的messages日志文件 HTTP/1.1 200 OK Server: nginx/1.14.2 Date: Sun, 07 Mar 2021 05:50:34 GMT Content-Type: text/html Content-Length: 632260 #不启用压缩时,报文头显示文件大小 Last-Modified: Sun, 07 Mar 2021 01:12:36 GMT Connection: keep-alive Vary: Accept-Encoding ETag: "60442884-9a5c4" Accept-Ranges: bytes
启用压缩后测试: [[email protected] conf.d]# curl -I --compressed www.magedu.org/messages HTTP/1.1 200 OK Server: nginx/1.14.2 Date: Sun, 07 Mar 2021 05:53:14 GMT Content-Type: text/html Last-Modified: Sun, 07 Mar 2021 01:12:36 GMT Connection: keep-alive Vary: Accept-Encoding ETag: W/"60442884-9a5c4" Content-Encoding: gzip #压缩后报文头标识
日志输出验证:
压缩前日志输出:
{"@timestamp":"2021-03-07T13:46:11+08:00","host":"10.0.0.126","clientip":"10.0.0.125","size":632260,"responsetime":0.024,"upstreamtime":"-","upstreamhost":"-","http_host":"www.magedu.org","uri":"/messages","domain":"www.magedu.org","xff":"-","referer":"-","tcp_xff":"","http_user_agent":"curl/7.29.0","status":"200"} 压缩后日志输出:
{"@timestamp":"2021-03-07T13:50:09+08:00","host":"10.0.0.126","clientip":"10.0.0.125","size":84067,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"www.magedu.org","uri":"/messages","domain":"www.magedu.org","xff":"-","referer":"-","tcp_xff":"","http_user_agent":"curl/7.29.0","status":"200"}
标签:www,http,压缩,magedu,nginx,gzip,org From: https://www.cnblogs.com/cnblogsfc/p/14517728.html