1. http_gzip_module
1.1 gzip
指令
Syntax: gzip on | off ;Default: gizp off ;Context: http,server,location,if in location
说明
1.2. gzip_buffers
指令
Syntax: gzip_buffers number size ;Default: gzip_buffers 32 4k|16 8k ;Context: http,server,location
说明
指定用于压缩响应的缓冲区大小,建议为内存页大小的整数倍,在0.7.28之后,默认为32 4k或者16 8k,具体取决于平台。一般不用设置。
1.3. gzip_comp_level
指令
Syntax: gzip_comp_level [1-9] ;Default: gzip_comp_level 1 ;Context: http,server,location
说明
压缩比例可以是 1-9,数值越大,压缩率越高,压缩后文件也越小,但是CPU资源消耗越大。如果并发小,CPU资源充足,设置为6-8,反之2-3即可。
1.4. gzip_disable
指令
Syntax: gzip_disable regex ... ;Default: CloseContext: http,server,location
说明
该指令在0.6.23版本之后出现。根据请求头中的 User-Agent 字段的值来判断是否开启压缩,一般针对 IE 6及以下版本关闭压缩,也可以不写,毕竟使用IE6情况过少。
一般使用 “MISE [4-6].“ 表示IE 6及更老的版本,使用”msie6” 代替”MISE [4-6].“速度更快,减少匹配时间。1.5. gzip_http_version
指令
Syntax: gzip_http_version 1.0|1.1 ;Default: gzip_http_version 1.1 ;Context: http,server,location
说明
1.6. gzip_min_length
指令
Syntax: gzip_min_length length ;Default: gzip_min_length 20 ;Context: http,server,location
说明
设置被压缩报文的最小长度,其值取自于Context-Length.建议设置为1024,过小的文件可能会越压越大!
1.7. gzip_proxied
指令
Syntax: gzip_proxied off|expired|no-cache|no-store|private|no_last_modified|no_etag|auth|any …Default: gzip_prixied off ;Context: http,server,location
说明
指定代理中的gzip配置,在测试环境中未搞明白机制,暂时先放一放。
1.8. gzip_types
指令
Syntax: gzip_types mime-type ... ;Default: gzip_types text/html ;Context: http,server,location
说明
指定压缩的MIME类型,* 表示所有类型都压缩,一般建议压缩文本类型,比如html,css,js,xml,json等。图片类压缩效果比较差
1.9. gzip_vary
指令
Syntax: gzip_vary on | off ;Default: gzip_vary off ;Context: http,server,location
说明
如果开启了gzip,gzip_static,gunzip等指令,将在响应头中显示 “Vary: Accept-Encoding” 字段
2. http_gzip_static_module
2.1. gzip_static
指令
Syntax: gzip_static on|off|always ;Default: gzip_static off ;Context: http,server,location
说明
该指令对于大文件下载非常有用,通过预先在资源目录下对需要下载的资源进行gzip压缩,生成.gz结尾的压缩文件,nginx直接将.gz文件返回给客户端。
该指令在使用时,会考虑到 gzip_http_version,gzip_proxied,gzip_disable和gzip_vary指令。
在1.3.6版本后,增加了always选项,设置该选项后,将不再检查客户端是否支持gzip压缩,对于目录下没有未压缩的文件或者开启了http_gunzip_module时很有用。
3. http_gunzip_module
3.1. gunzip
指令
Syntax: gunzip on|off ;Default: gunzip off ;Context: http,server,location
说明
针对不支持gzip压缩的客户端,nginx服务器将解压响应资源,并将解压后的内容返回给客户端。
如果启用,该指令还会通过以下指令判断客户端是否支持gzip压缩:gzip_http_version,gzip_proxied,gzip_disable
3.2. gunzip_buffers
指令
Syntax: gunzip_buffers number size ;Default: gunzip_buffers 32 4k|16 8k ;Context: http,server,location
说明
3.2. 反向代理中gunzip效果
配置: 后端的nginx,httpd均开启压缩;前端gzip on时,对IE 6及以下版本不压缩
| nginx | proxy | gzip off ; gunzip off | gzip on ; gunzip off | gzip off ; gunzip on | gzip on ; gunzip on | | —- | —- | —- | —- | —- | —- | | nginx | IE 6 | gunzip | gunzip | gunzip | gunzip | | nginx | IE 9 | gunzip | gzip | gunzip | gzip | | httpd | IE 6 | gzip | gzip | gunzip | gunzip | | httpd | IE 9 | gzip | gzip | gzip | gzip |
从上述结论可以看到: 针对反向代理的情况,直接使用 gunzip on ;一键解决问题。或者后端服务器不压缩,全部交由代理服务器压缩。
4. 案例
4.1. gzip案例
4.1.1. 配置项
[root@centos-81 ~]# cat /etc/nginx/nginx.conf
gzip on ;gzip_min_length 1024 ;gzip_types text/css text/plain application/javascript application/xml image/gif image/jpeg image/png;gzip_disable msie6 ;
- 开启gzip压缩
- 最小压缩长度 1024
- 支持图片和文本(text/html 没必要写,因为写了会提示nginx: [warn] duplicate MIME type “text/html” in /etc/nginx/nginx.conf)
- IE 6及以下版本不压缩
- 压缩级别1
-
4.1.2. 针对资源类型测试
[root@centos-50 ~]# curl -I -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0” 192.168.1.81/index.htm ## text/html is compress defalut.
HTTP/1.1 200 OKServer: nginx/1.14.2Date: Sat, 29 Dec 2018 03:46:00 GMTContent-Type: text/htmlLast-Modified: Tue, 14 Nov 2017 10:36:39 GMTConnection: keep-aliveETag: W/"5a0ac737-5dc8"Content-Encoding: gzip
[root@centos-50 ~]# curl -I -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0” http://192.168.1.81/gtzx/tpxw/201705/W020170801791558756653.jpeg
HTTP/1.1 200 OKServer: nginx/1.14.2Date: Sat, 29 Dec 2018 03:50:16 GMTContent-Type: image/jpegLast-Modified: Tue, 01 Aug 2017 14:08:35 GMTConnection: keep-aliveETag: W/"59808b63-385800"Content-Encoding: gzip
[root@centos-50 ~]# curl -I -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1;Trident/5.0” http://192.168.1.81/a.pdf
HTTP/1.1 200 OKServer: nginx/1.14.2Date: Sat, 29 Dec 2018 03:53:49 GMTContent-Type: application/pdfContent-Length: 192088019Last-Modified: Thu, 01 Mar 2018 12:22:50 GMTConnection: keep-aliveETag: "5a97f09a-b7307d3"Accept-Ranges: bytes
4.1.3. 针对user-agent测试
[root@centos-50 ~]# curl -I -H “Accept-Encoding: gzip, deflate” -A “User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)” 192.168.1.81/gtzx/tpxw/201705/W020170801791558756653.jpeg # IE 6
HTTP/1.1 200 OKServer: nginx/1.14.2Date: Sat, 29 Dec 2018 03:56:11 GMTContent-Type: image/jpegContent-Length: 3692544Last-Modified: Tue, 01 Aug 2017 14:08:35 GMTConnection: keep-aliveETag: "59808b63-385800"Accept-Ranges: bytes
[root@centos-50 ~]# curl -I -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0” 192.168.1.81/gtzx/tpxw/201705/W020170801791558756653.jpeg # IE 9
HTTP/1.1 200 OKServer: nginx/1.14.2Date: Sat, 29 Dec 2018 03:56:27 GMTContent-Type: image/jpegLast-Modified: Tue, 01 Aug 2017 14:08:35 GMTConnection: keep-aliveETag: W/"59808b63-385800"Content-Encoding: gzip
[root@centos-50 ~]# curl -I -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Opera/9.80 (Windows NT 6.1; U; zh-cn) Presto/2.9.168 Version/11.50” 192.168.1.81/gtzx/tpxw/201705/W020170801791558756653.jpeg # Opera
HTTP/1.1 200 OKServer: nginx/1.14.2Date: Sat, 29 Dec 2018 03:57:24 GMTContent-Type: image/jpegLast-Modified: Tue, 01 Aug 2017 14:08:35 GMTConnection: keep-aliveETag: W/"59808b63-385800"Content-Encoding: gzip
[root@centos-50 ~]# curl -I -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1” 192.168.1.81/gtzx/tpxw/201705/W020170801791558756653.jpeg # chrome
HTTP/1.1 200 OKServer: nginx/1.14.2Date: Sat, 29 Dec 2018 03:58:37 GMTContent-Type: image/jpegLast-Modified: Tue, 01 Aug 2017 14:08:35 GMTConnection: keep-aliveETag: W/"59808b63-385800"Content-Encoding: gzip
4.1.4. gzip_proxied测试
在官方文档中存在以下描述:

理论上来说:默认情况下针对反向代理的响应,应该不会进行gzip压缩,但是测试结果与其相悖:
[root@centos-50 ~]# curl -I -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1” http://192.168.1.81/gtwzqxxgk/imagesls/xxgk_sxzy.cssHTTP/1.1 200 OKServer: nginx/1.14.2Date: Sat, 29 Dec 2018 04:05:33 GMTContent-Type: text/cssConnection: keep-aliveLast-Modified: Tue, 09 Jan 2018 03:07:43 GMTETag: W/"106f-5624f37e13dc0"Access-Control-Allow-Origin: http://www.jsmlr.gov.cn:80/gtxx/Content-Encoding: gzip
目前能想到的解决方案: 在反向代理的location中使用 gzip off
[root@centos-81 ~]# cat /etc/nginx/conf.d/localhost.conflocation ~ ^/gt[a-z]+ {gzip off ;proxy_pass http://www.jsmlr.gov.cn ;}
[root@centos-50 ~]# curl -I -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1” http://192.168.1.81/gtwzqxxgk/imagesls/xxgk_sxzy.css
HTTP/1.1 200 OKServer: nginx/1.14.2Date: Sat, 29 Dec 2018 04:07:54 GMTContent-Type: text/cssContent-Length: 4207Connection: keep-aliveLast-Modified: Tue, 09 Jan 2018 03:07:43 GMTETag: "106f-5624f37e13dc0"Accept-Ranges: bytesAccess-Control-Allow-Origin: http://www.jsmlr.gov.cn:80/gtxx/
4.2. gzip static module案例
针对附件下载的location使用该方式可以降低cpu消耗,服务端直接将预压缩文件(.gz)传给客户端。
4.2.1. 配置
[root@centos-81 ~]# cat /etc/nginx/conf.d/localhost.conf
location /download {root /usr/share/nginx/html ;gzip_static on ;sendfile on ;}
[root@centos-81 download]# gzip -c a.pdf -9 > a.pdf.gz ## 测试文件
4.2.2. 测试
支持gzip的user-agent
[root@centos-50 ~]# curl -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0” http://192.168.1.81/download/a.pdf | gunzip > a.pdf ## receive compress file.
% Total % Received % Xferd Average Speed Time Time Time CurrentDload Upload Total Spent Left Speed100 178M 100 178M 0 0 98.9M 0 0:00:01 0:00:01 --:--:-- 98.9M
- 不支持gzip的user-agent
[root@centos-50 ~]# curl -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)” http://192.168.1.81/download/a.pdf > b.pdf ## receive uncompress file.
% Total % Received % Xferd Average Speed Time Time Time CurrentDload Upload Total Spent Left Speed100 183M 100 183M 0 0 162M 0 0:00:01 0:00:01 --:--:-- 162M
- 移除源文件的后,不支持的user-agent将收到404,nignx不会解压.gz的资源,即使使用gunzip
[root@centos-50 ~]# curl -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)” http://192.168.1.81/download/a.pdf ## raise 404.
<html><head><title>404 Not Found</title></head><body bgcolor="white"><center><h1>404 Not Found</h1></center><hr><center>nginx/1.14.2</center></body></html><!-- a padding to disable MSIE and Chrome friendly error page --><!-- a padding to disable MSIE and Chrome friendly error page --><!-- a padding to disable MSIE and Chrome friendly error page --><!-- a padding to disable MSIE and Chrome friendly error page --><!-- a padding to disable MSIE and Chrome friendly error page --><!-- a padding to disable MSIE and Chrome friendly error page -->
4.3. gunzip案例
4.3.1. 代理服务的结构与配置
| 前端 | location | 后端服务器 | 后端服务器gzip开关 |
|---|---|---|---|
| nginx | proxy/ | nginx | gzip on |
| nginx | httpd/ | httpd | gzip on |
[root@centos-81 conf.d]# cat /etc/nginx/nginx.conf # 前端nginx.conf配置
gzip on ;gzip_min_length 1024 ;gzip_types text/css text/plain application/javascript application/xml image/gif image/jpeg image/png;gzip_disable msie6 ;include /etc/nginx/conf.d/*.conf;
4.3.2. gzip off ; gunzip off
前端location中gizp与gunzip配置
location /proxy {proxy_pass http://192.168.1.50 ;gzip off ;gunzip off ;}location /httpd {proxy_pass http://192.168.1.50:8080 ;gzip off ;gunzip off ;}
后端nginx
[root@centos-81 conf.d]# curl -I -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)” 192.168.1.81/proxy/a.txt ## IE 6 (unzip) —OK
HTTP/1.1 200 OKServer: nginx/1.14.2Date: Sun, 30 Dec 2018 08:33:36 GMTContent-Type: text/plainContent-Length: 99727Connection: keep-aliveLast-Modified: Fri, 28 Dec 2018 01:48:35 GMTETag: "5c2580f3-1858f"Accept-Ranges: bytes
[root@centos-81 conf.d]# curl -I -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1 Trident/5.0” 192.168.1.81/proxy/a.txt## IE 9 (unzip) —OK
HTTP/1.1 200 OKServer: nginx/1.14.2Date: Sun, 30 Dec 2018 08:04:49 GMTContent-Type: text/plainContent-Length: 99727Connection: keep-aliveLast-Modified: Fri, 28 Dec 2018 01:48:35 GMTETag: "5c2580f3-1858f"Accept-Ranges: bytes
- 后端httpd:
[root@centos-81 conf.d]# curl -I -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0” 192.168.1.81/httpd/a.txt ## IE 6 (zip) —ERROR
HTTP/1.1 200 OKServer: nginx/1.14.2Date: Sun, 30 Dec 2018 08:13:41 GMTContent-Type: text/plain; charset=UTF-8Content-Length: 13110Connection: keep-aliveLast-Modified: Fri, 28 Dec 2018 15:57:19 GMTETag: "100b25-1858f-57e171e30b7c5"Accept-Ranges: bytesVary: Accept-EncodingContent-Encoding: gzip
[root@centos-81 conf.d]# curl -I -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)” 192.168.1.81/httpd/a.txt ## IE 9 (zip) —OK
HTTP/1.1 200 OKServer: nginx/1.14.2Date: Sun, 30 Dec 2018 08:15:36 GMTContent-Type: text/plain; charset=UTF-8Content-Length: 13110Connection: keep-aliveLast-Modified: Fri, 28 Dec 2018 15:57:19 GMTETag: "100b25-1858f-57e171e30b7c5"Accept-Ranges: bytesVary: Accept-EncodingContent-Encoding: gzip
4.3.3. gzip on ; gunzip off
前端location中gizp与gunzip配置
location /proxy {proxy_pass http://192.168.1.50 ;# gzip off ;gunzip off ;}location /httpd {proxy_pass http://192.168.1.50:8080 ;# gzip off ;gunzip off ;}
后端nginx: [root@centos-81 conf.d]# curl -I -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)” 192.168.1.81/proxy/a.txt ## IE 6 (unzip) —OK
HTTP/1.1 200 OKServer: nginx/1.14.2Date: Sun, 30 Dec 2018 08:18:14 GMTContent-Type: text/plainContent-Length: 99727Connection: keep-aliveLast-Modified: Fri, 28 Dec 2018 01:48:35 GMTETag: "5c2580f3-1858f"Accept-Ranges: bytes
[root@centos-81 conf.d]# curl -I -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0” 192.168.1.81/proxy/a.txt ## IE 9 (zip) —OK
HTTP/1.1 200 OKServer: nginx/1.14.2Date: Sun, 30 Dec 2018 08:19:10 GMTContent-Type: text/plainConnection: keep-aliveLast-Modified: Fri, 28 Dec 2018 01:48:35 GMTETag: W/"5c2580f3-1858f"Content-Encoding: gzip
后端httpd:
[root@centos-81 conf.d]# curl -I -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)” 192.168.1.81/httpd/a.txt ## IE 6 (zip) —ERROR
HTTP/1.1 200 OKServer: nginx/1.14.2Date: Sun, 30 Dec 2018 08:20:48 GMTContent-Type: text/plain; charset=UTF-8Content-Length: 13110Connection: keep-aliveLast-Modified: Fri, 28 Dec 2018 15:57:19 GMTETag: "100b25-1858f-57e171e30b7c5"Accept-Ranges: bytesVary: Accept-EncodingContent-Encoding: gzip
[root@centos-81 conf.d]# curl -I -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0” 192.168.1.81/httpd/a.txt ## IE 9 (zip) —OK
HTTP/1.1 200 OKServer: nginx/1.14.2Date: Sun, 30 Dec 2018 08:21:18 GMTContent-Type: text/plain; charset=UTF-8Content-Length: 13110Connection: keep-aliveLast-Modified: Fri, 28 Dec 2018 15:57:19 GMTETag: "100b25-1858f-57e171e30b7c5"Accept-Ranges: bytesVary: Accept-EncodingContent-Encoding: gzip
4.3.4. gzip off ; gunzip on
前端location中gizp与gunzip配置
location /proxy {proxy_pass http://192.168.1.50 ;gzip off ;gunzip on ;}location /httpd {proxy_pass http://192.168.1.50:8080 ;gzip off ;gunzip on ;}
后端nginx
[root@centos-81 conf.d]# curl -I -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)” 192.168.1.81/proxy/a.txt ## IE 6 (unzip) —OK
HTTP/1.1 200 OKServer: nginx/1.14.2Date: Sun, 30 Dec 2018 08:24:26 GMTContent-Type: text/plainContent-Length: 99727Connection: keep-aliveLast-Modified: Fri, 28 Dec 2018 01:48:35 GMTETag: "5c2580f3-1858f"Accept-Ranges: bytes
[root@centos-81 conf.d]# curl -I -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0” 192.168.1.81/proxy/a.txt ## IE 9 (unzip) —OK
HTTP/1.1 200 OKServer: nginx/1.14.2Date: Sun, 30 Dec 2018 08:24:58 GMTContent-Type: text/plainContent-Length: 99727Connection: keep-aliveLast-Modified: Fri, 28 Dec 2018 01:48:35 GMTETag: "5c2580f3-1858f"Accept-Ranges: bytes
- 后端httpd
[root@centos-81 conf.d]# curl -I -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)” 192.168.1.81/httpd/a.txt ## IE 6 (unzip) —OK
HTTP/1.1 200 OKServer: nginx/1.14.2Date: Sun, 30 Dec 2018 08:25:48 GMTContent-Type: text/plain; charset=UTF-8Connection: keep-aliveLast-Modified: Fri, 28 Dec 2018 15:57:19 GMTETag: W/"100b25-1858f-57e171e30b7c5"Vary: Accept-Encoding
[root@centos-81 conf.d]# curl -I -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0” 192.168.1.81/httpd/a.txt ## IE 9 (zip) —OK
HTTP/1.1 200 OKServer: nginx/1.14.2Date: Sun, 30 Dec 2018 08:25:57 GMTContent-Type: text/plain; charset=UTF-8Content-Length: 13110Connection: keep-aliveLast-Modified: Fri, 28 Dec 2018 15:57:19 GMTETag: "100b25-1858f-57e171e30b7c5"Accept-Ranges: bytesVary: Accept-EncodingContent-Encoding: gzip
4.3.4. gzip on ; gunzip on
前端location中gizp与gunzip配置
location /proxy {proxy_pass http://192.168.1.50 ;gunzip on ;}location /httpd {proxy_pass http://192.168.1.50:8080 ;gunzip on ;}
后端ngin
[root@centos-81 conf.d]# curl -I -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)” 192.168.1.81/proxy/a.txt ## IE 6 (unzip) —OK
HTTP/1.1 200 OKServer: nginx/1.14.2Date: Sun, 30 Dec 2018 08:29:50 GMTContent-Type: text/plainContent-Length: 99727Connection: keep-aliveLast-Modified: Fri, 28 Dec 2018 01:48:35 GMTETag: "5c2580f3-1858f"Accept-Ranges: bytes
[root@centos-81 conf.d]# curl -I -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0” 192.168.1.81/proxy/a.txt ## IE 9 (zip) —OK
HTTP/1.1 200 OKServer: nginx/1.14.2Date: Sun, 30 Dec 2018 08:30:11 GMTContent-Type: text/plainConnection: keep-aliveLast-Modified: Fri, 28 Dec 2018 01:48:35 GMTETag: W/"5c2580f3-1858f"Content-Encoding: gzip
- 后端httpd
[root@centos-81 conf.d]# curl -I -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)” 192.168.1.81/httpd/a.txt ## IE 6 (unzip) —OK
HTTP/1.1 200 OKServer: nginx/1.14.2Date: Sun, 30 Dec 2018 08:30:39 GMTContent-Type: text/plain; charset=UTF-8Connection: keep-aliveLast-Modified: Fri, 28 Dec 2018 15:57:19 GMTETag: W/"100b25-1858f-57e171e30b7c5"Vary: Accept-Encoding
[root@centos-81 conf.d]# curl -I -H “Accept-Encoding: gzip, deflate” -A “User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0” 192.168.1.81/httpd/a.txt ## IE 9 (zip) —OK
HTTP/1.1 200 OKServer: nginx/1.14.2Date: Sun, 30 Dec 2018 08:31:04 GMTContent-Type: text/plain; charset=UTF-8Content-Length: 13110Connection: keep-aliveLast-Modified: Fri, 28 Dec 2018 15:57:19 GMTETag: "100b25-1858f-57e171e30b7c5"Accept-Ranges: bytesVary: Accept-EncodingContent-Encoding: gzip
4.3.5. 实验结论
| nginx | proxy | gzip off ; gunzip off | gzip on ; gunzip off | gzip off ; gunzip on | gzip on ; gunzip on | | —- | —- | —- | —- | —- | —- | | nginx | IE 6 | gunzip | gunzip | gunzip | gunzip | | nginx | IE 9 | gunzip | gzip | gunzip | gzip | | httpd | IE 6 | gzip | gzip | gunzip | gunzip | | httpd | IE 9 | gzip | gzip | gzip | gzip |
