How To Fix "gzip is failing for js files" Nginx

| Servers | 14 seen

From Drupal Reports status page I noticed gzip is failing for js files error

The web servers configuration will need to be adjusted. In most cases make sure that the webroots .htaccess file still contains this section "Rules to correctly serve gzip compressed CSS and JS files". Certain default web server configurations (nginx) do not gzip HTTP/1.0 requests. If you are using cloudfront you will have to add metadata to the .gz files. There are some other options if using cloudfront.

For Nginx web servers there is an easy fix, adding just a few lines of code to the server block

here is the fix (source: Enable GZIP for CSS and JS files on NGINX server for Magento)

sudo nano /etc/nginx/sites-available/yourdomain.com

copy following under the server config

    gzip on;
    gzip_http_version 1.0;
    gzip_disable "msie6";
        gzip_vary on;
        gzip_proxied any;
        gzip_comp_level 6;
        gzip_buffers 16 8k;
        gzip_min_length 256;
  gzip_types
    text/css
    text/javascript
    text/xml
    text/plain
    text/x-component
    application/javascript
    application/json
    application/xml
    application/rss+xml
    font/truetype
    font/opentype
    application/vnd.ms-fontobject
    image/svg+xml;

Restart Nginx

sudo service nginx restart

Add new comment