I use on my servers varnish 7.1.2 and I want to upgrade to varnish 7.4.2 Everything is OK but since I've make the upgrade, I've noticed a strange behaviour: When I made a curl, I see that VARY cookie is changed from:
vary: Accept-Encoding, Cookie, User-Agent - CORRECT
to
vary: User-Agent, Cookie - WRONG
This translates into a huge increasing in network usage, becouse it seems that the content is no more compressed both when varnish gets it from the backend, and in the communication between the client and varnish.
After a lot of searching, I've added to function vcl_backend_response this:
if (beresp.http.content-type ~ "text") {
set beresp.do_gzip = true;
}
The situation seems improving, as the client receives the compressed content and the "accept-encoding" appears again on the vary cookie. However, it seems that when varnish fetches content from the backend, it is always uncompressed and therefore network occupancy still remains high.
For the moment I have decided to roll back to 7.1.2 but it is still not a sustainable solution in the long term.
Can anyone help me understand?
Thanks a lot
I've tested this using different versions of the official Varnish Docker image. To be honest: I can't spot any behavioral differences between the different versions.
I used the
varnish:latest
,varnish:7.1
and evenvarnish:stable
to perform the tests. In all the test scenarios onlyVary: Cookie, User-Agent
came out. I didn't spot theAccept-Encoding
header in theVary
header on any of the versions.Ensure your backend returns gzip-encoded responses
This led me to do some more research and turns out the standard
nginx:alpine
image I'm using for the test doesn't have gzip enabled in the vhost configuration.This means that if your backend server doesn't return a
Content-Encoding: gzip
header, Varnish will not add aVary: Accept-Encoding
variation.Setting
gzip on;
in my Nginx config didn't help. Apparently settinggzip_proxied any;
did the trick, and all of the sudden I'm getting aVary: Cookie, User-Agent, Accept-Encoding
header.I'm not saying my solution will work for you, but it's worth checking if your backend is actually returning gzip-encoded content.
Troubleshooting
You can use the following command to debug this in Varnish:
Be sure to run this on a empty cache in order to catch the backend fetch. This example also assumes we're testing this on the home page
The output could look like this for gzip-encoded content:
For plain text output, this is what the output could look like:
Conclusion
There don't seem to be any behavioral changes in Varnish regarding GZIP compression and cache variations.
Varnish will only add
Vary: Accept-Encoding
if the backend actually returns gzip-encoded content. Web server configurations prevent gzip-encoded content for proxied requests.Please use the troubleshooting tips mentioned above to examine this.