What is “Specify a Vary: Accept-Encoding header” warning and how to fix it

It’s possible that you will run into the “Specify a Vary: Accept-Encoding header” warning when checking your website performance. But what exactly does this mean? How can you fix this?

In this article, you will learn what the error is and how to resolve the issue.
What is this warning?
Before we dive into how to fix this issue, let’s first understand what the “Specify a Vary: Accept-Encoding header” warning means and how to check if your site is affected.
You can typically find this error on websites that run on web servers as Nginx and Apache.
What does “Specify a Vary: Accept-Encoding header” actually mean?
An Accept-Encoding header is an HTTP header that must be included on every origin server response. Its main job is to inform the browsers if the client can handle the compressed version of the website.
The warning can appear when you don’t use Vary: Accept-Encoding in your header on a server or CDN. This will cause either of them to deliver the uncompressed version of your website to modern browsers.
While not on purpose, this can actually affect your site’s performance in front of the clients, though it’s not major.
Where to find the warning?
If you want to check whether your website is affected, you can conduct a performance analysis using tools like Pingdom or GTmetrix.
After entering your website’s URL, performance analyzers will highlight any errors. But worry not; we’ll tell you how to fix the problem easily.
Fixing “Specify a Vary: Accept-Encoding header”
This tutorial will require you to insert several lines of code, requiring a bit of technical knowledge. If you’re not sure, you might need to call a professional to help you.
Let’s check out how to fix the “Specify a Vary: Accept-Encoding header” warning on the two most popular web servers: Nginx and Apache.
NGINX
To fix this issue on Nginx, you need to navigate to the primary configuration in your VPS via SSH. The location is at /etc/nginx/nginx.conf.
If you’re not sure how to access your VPS, check out our PuTTY SSH tutorial!
Once you find the file, you need to add or modify the line gzip_vary:
gzip_vary on
For this, feel free to use your preferred text editor.
Then, save it and restart the Apache service. Your error should be fixed now.
Apache
While you have to know how to access your VPS using the SSH command on an Nginx server, resolving the warning on Apache is a bit simpler.
You only need an FTP client like FileZilla to navigate to your website’s files. Then, you should find and edit your .htaccess file.
However, be very careful when editing files through FTP. It is highly recommended that you perform a file backup in case anything goes wrong.
Once you’re ready with the .htaccess, you will have to add or modify this snippet to look exactly like this:
<IfModule mod_headers.c> <FilesMatch ".(js|css|xml|gz|html)$"> Header append Vary: Accept-Encoding </FilesMatch> </IfModule>
Conclusion
Fixing the “Vary: Accept-Encoding header” is relatively easy when you follow our instructions correctly, either on an Apache or an Nginx server. However, you will need to be careful and create a backup before making any changes to avoid issues with your site or server.
Learn More Aout Website Maintenance
Website Maintenance Cost
How to Diagnose and Fix a Hacked Website
Website Uptime and Downtime
How to Clear Browser Cache and History
How to Inspect Element
How to Use Cookie-Free Domains
How to Check Your Website’s PHP Error Log
All of the tutorial content on this website is subject to Hostinger's rigorous editorial standards and values.
Comments
June 21 2022
How to remove Vary headers. We have our ngnix.cnf file inside ngnix/conf/ngnix.conf. ther is nothing related to vary and still we are getting Vary:Accept-Encoding
July 01 2022
Hey! If Vary headers are getting added automatically, you can use the command
gzip_vary off;
to prevent it. You can learn more about it by checking out this resource!?