I'm trying to active gzip compression and I have set the option gzip_vary on; to include the Vary: Accept-Encoding header.

The problem is, my application is already seting a Vary: header. So the response is now having two Vary: headers, one from my application and one from nginx.

HTTP/1.1 200 OK
Server: nginx
Date: Sat, 17 Dec 2016 13:28:38 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding
Last-Modified: Sat, 17 Dec 2016 13:28:38 GMT
Cache-Control: no-cache, no-store, must-revalidate, max-age=0
Pragma: no-cache
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Vary: User-Agent
Content-Encoding: gzip

But I guess instead it should be rather like this:

Vary: Accept-Encoding, User Agent

How can I achieve this?


2 Answers 2


RFC2616 states duplicate headers are acceptable and should be treated the same as a single header with a comma-separated list of values:

Multiple message-header fields with the same field-name MAY be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)]. It MUST be possible to combine the multiple header fields into one "field-name: field-value" pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma. The order in which header fields with the same field-name are received is therefore significant to the interpretation of the combined field value, and thus a proxy MUST NOT change the order of these field values when a message is forwarded.

So, you don't need to do anything to get the proper behavior.

  • Thanks; I think you're right. I have checked and our Varnish caches seem happy enough with multiple "Vary" headers, so this isn't actually a problem.
    – Rich
    Feb 13, 2017 at 15:45

You can use gzip in that way.

gzip on;
gzip_http_version 1.1;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js image/gif image/jpeg application/atom+xml application/rss+xml text/x-component image/png image/tiff image/vnd.wap.wbmp image/x-icon image/x-jng image/x-ms-bmp image/svg+xml image/webp application/font-woff application/msword application/pdf;
gzip_buffers 16 8k;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";

Check this link for more Compress traffic between uwsgi-nginx and nginx load balancer

  • 2
    (I don't think this answers the question that is being asked here)
    – Rich
    Feb 16, 2017 at 14:38

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.