I have an nginx server and can't seem to find any information on how to send Vary: Accept-Encoding headers for CSS and JS files. Does anyone have info about this?
Thanks!
I have an nginx server and can't seem to find any information on how to send Vary: Accept-Encoding headers for CSS and JS files. Does anyone have info about this?
Thanks!
If you've tried the other answers and are still seeing vary off (e.g. if you are testing speed of your page using GTMetrix), the following might help:
Make sure all your gzip_types are also set in /etc/nginx/nginx.conf http section.
The server block in /etc/nginx/sites-available/* is one place where you can set the vary header and gzip_types, but depending on how you have your site setup you may be processing and returning files before they reach that bit of config.
In /etc/nginx/nginx.conf you will find an 'http' section - in here, there is also a gzip_types and gzip_vary.
For me - CSS and JS are static files and were being served up before hitting the (wordpress) nginx sites-available file (I have varnish in front of it).
So adding the full list of gzip_types to the http section in nginx.conf fixed my issue.
This is from the nginx documentation.
There if you just add
gzip_vary on;
it should do it's job.Also make sure you have any one of the directives gzip, gzip_static, or gunzip are active.
Simple. In Nginx conf:
Add the following near the bottom under the section:
Just uncomment the
gzip_vary on;
parameter and restart or reload nginx service:This should fix the issue. If you are running an old version of nginx, you may need to enable
gzip on;
, as this is required for the vary header to work.I hope this helps. FYI, this applies to all server/site conf files unless overwritten in their own respective server blocks.
server {}
Source info for nginx, apache and IIS: https://www.maxcdn.com/blog/accept-encoding-its-vary-important/
Inside the
server {
of the domain/subdomain that you want to set it, addSave the file and restart nginx.