I need to disable gzip in some cases, regardless of client's Accept-* request headers.

My Nginx's conf entry has the following directives:

gzip off;

more_clear_input_headers -t 'text/html' Accept Accept-Encoding;

proxy_set_header Accept "";
proxy_set_header Accept-Encoding "";

However, the following curl:

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

Results with:

< 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

Note, the responding server is proxied by this Nginx.

  • You cannot enforce the responding server not to gzip content? – Tero Kilkanen Sep 1 '16 at 9:55
  • What is "Reblaze Secure Web Gateway"? – Michael Hampton Sep 1 '16 at 10:15
  • If the upstream server is setting the Content-Encoding header and sending the data as gziped, then your Nginx proxy configuration won't change that. Nginx is not going to extract the compressed data in order to send it uncompressed - it will send the response as-is. You likely need to turn off gzip on the backend server in order to do what you want. – Moshe Katz Sep 1 '16 at 19:45
  • I think @MichaelHampton has it on the nose, as usual. I believe his subtle message suggests there may be a proxy between you and Nginx that's doing gzip. – Tim Sep 1 '16 at 19:59
  • 1
    @MichaelHampton This is our own Nginx fork. – Tzury Bar Yochay Sep 7 '16 at 14:53

Apparently, this is not an Nginx "misbehaviour" rather, a proxied device, F5 BigIP in this case, which is configured to compress responses regardless of request headers, as long as the User-Agent header matches certain patterns.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.