Why is Apache sending duplicate Vary: Accept Encoding headers?

We put our Magento site on Sucuri and it is much slower than running it off our own server. Looking further, we notice that Apache is sending two Vary: Accept-Encoding headers and, as per Sucuri support, these duplicate headers are preventing the site from being cached properly by Sucuri CDN.

Here’s the curl output:

curl -IL
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 26 Jun 2017 15:21:07 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding |------> First header

Set-Cookie: frontend=fotji70ieh366b5k165u3mcd63; expires=Mon, 26-Jun-2017 16:22:19 GMT; Max-Age=3600; path=/;; HttpOnly
Expires: Mon, 26 Jun 2017 18:22:19 GMT
Cache-Control: public, max-age=10800
Last-Modified: Wed, 14 Sep 2016 07:13:12 GMT
Set-Cookie: frontend_cid=sugOUAWt3WMknsbW; expires=Mon, 26-Jun-2017 16:22:19 GMT; Max-Age=3600; path=/;; secure; httponly
X-Frame-Options: SAMEORIGIN
Strict-Transport-Security: max-age=31536000

Vary: Accept-Encoding,User-Agent |------> Second header
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Sucuri-Cache: MISS
X-Sucuri-ID: 16007

I have gone nuts trying to figure out why these duplicate headers are occurring. I removed mod_deflate and mod_expires <IfModule> declarations from the Apache vhost and Magento’s .htaccess but the duplicate headers are still showing up.

I would greatly appreciate any pointers towards fixing this. Thanks in advance.

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

This question was answered by @cloudnine:

Just figured out the answer, finally! Magento’s .htaccess had this additional <IfModule> declaration that was causing the second Vary: Accept-Encoding header:

<IfModule mod_mime.c>
      AddEncoding gzip              svgz

Commenting it out did the trick.

View the original comment