![在 Nginx 上强制不使用 Gzip](https://linux22.com/image/689134/%E5%9C%A8%20Nginx%20%E4%B8%8A%E5%BC%BA%E5%88%B6%E4%B8%8D%E4%BD%BF%E7%94%A8%20Gzip.png)
在某些情况下,我需要禁用 gzip,无论客户端的Accept-*
请求标头是什么。
我的 Nginx 的 conf 条目有以下指令:
gzip off;
more_clear_input_headers -t 'text/html' Accept Accept-Encoding;
proxy_set_header Accept "";
proxy_set_header Accept-Encoding "";
但是,以下卷曲:
curl '$URL'
-H 'Pragma: no-cache'
-H 'Accept-Encoding: gzip, deflate, sdch'
-H 'Accept-Language: en-US,en;q=0.8,he;q=0.6'
-H 'Upgrade-Insecure-Requests: 1'
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36'
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
-H 'Cache-Control: no-cache'
-H 'Cookie: "$COOKIE"'
-H 'Connection: keep-alive' -v > /dev/null
结果:
< HTTP/1.1 200 OK
< Cache-Control: no-cache, no-store, private
< Content-Encoding: gzip
< Content-Type: text/html;charset=utf-8
< Date: Thu, 01 Sep 2016 07:13:30 GMT
< Expires: -1
< Server: Reblaze Secure Web Gateway
< Set-Cookie: ...
< Set-Cookie: ...
< Set-Cookie: ...
< Set-Cookie: ...
< Set-Cookie: ...
< Set-Cookie: ...
< Set-Cookie: ...
< Vary: User-Agent
< Content-Length: 55455
< Connection: keep-alive
注意,响应的服务器由此 Nginx 代理。
答案1
显然,这不是 Nginx 的“不当行为”,而是一个代理设备,在本例中是 F5 BigIP,它配置为无论请求标头如何,只要 User-Agent 标头匹配某些模式,就会压缩响应。