Nginx Docker – Missing Vary: Accept-Encoding Header

dockerhttphttpsnginx

I'm serving a static website from nginx that runs on a docker container which is based on nginx:alpine base image.

My DockerFile:

FROM nginx:alpine
COPY --from=angular-built app/dist/dayTwoApp /usr/share/nginx/html
COPY ./default.conf /etc/nginx/conf.d/default.conf

The default.conf file:

server {
   listen 80;

    gzip on;
    gzip_vary on;
    gzip_types    text/plain application/javascript application/x-javascript text/javascript text/xml text/css;

    access_log  /var/log/nginx/access.log;
    error_log   /var/log/nginx/error.log;

    root /usr/share/nginx/html;
    index index.html index.htm;

    location / {
        try_files $uri $uri/ /index.html;
    }
}

I see the vary : Accept-Encoding header in the response from a served html file (see below).

But for some reason i don't see the header in the js and css responses.

(*) Relevant references which didn't work:

Details of responses:

html file:

enter image description here

js files (also for css):

enter image description here

Best Answer

Please try adding to your nginx configuration:

gzip_proxied any
gzip_types
    text/plain
    text/css
    text/js
    text/xml
    text/javascript
    application/javascript
    application/x-javascript
    application/json
    application/xml
    application/rss+xml
    image/svg+xml;

(Only responses with the “text/html” type are always compressed.)