perusio / drupal-with-nginx

Running Drupal using nginx: an idiosyncratically crafted bleeding edge configuration.
854 stars 246 forks source link

Nginx doesn't compress CSS files. #267

Closed pprishchepa closed 7 years ago

pprishchepa commented 7 years ago

I'm trying to figure out why Nginx doesn't compress CSS. Nginx config looks valid and typical for the tasks like that.

Failed test:

curl -H "Accept-Encoding: gzip" -I https://<hostname>/sites/default/files/css/css_xLFDRTFqZTZeUg7Pab0gP4cpz5TWo3PCH-KBo_HKQ6A.css

HTTP/1.1 200 OK
Server: nginx
Content-Type: text/css
Content-Length: 1123
ETag: "587c4cdc-463"
Cache-Control: max-age=2592000
Accept-Ranges: bytes

The response Content-Encoding should be gzip instead of text/css.

Nginx config:

http {
...
    gzip                                on;
    gzip_buffers                        16 8k;
    gzip_comp_level                     2;
    gzip_http_version                   1.1;
    gzip_min_length                     10240;
    gzip_types                          text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/x-icon application/vnd.ms-fontobject font/opentype application/x-font-ttf;
    gzip_vary                           on;
    gzip_proxied                        any;
    gzip_disable                        msie6;
...
}
pprishchepa commented 7 years ago

Solved in http://stackoverflow.com/questions/41799062/nginx-doesnt-compress-css-files. The issue was caused by too large gzip_min_length.