Enabling Gzip compression guidance needed

September 4, 2019 457 views
Nginx Ubuntu 16.04

Hi, Guys

I am following this tutorial https://www.digitalocean.com/community/tutorials/how-to-add-the-gzip-module-to-nginx-on-ubuntu-16-04, but when testing, the output is different. It seems something is not working for me.

After following the steps in the tutorial, when testing:

curl -H "Accept-Encoding: gzip" -I http://localhost/test.jpg

The output is:

HTTP/1.1 301 Moved Permanently
Server: nginx/1.10.3 (Ubuntu)
Date: Wed, 04 Sep 2019 18:33:30 GMT
Content-Type: text/html
Content-Length: 194
Connection: keep-alive
Location: https://radha.org.br/test.jpg

So the header Content-Encoding: gzip is not appearing.

Another question is that i have two wordpress websites in my droplet. This configuration will impact the two of them or i have to configure each site separatedly for Gzip compression to work?

Anyway, i followed the tutorial until its end and after that i gave a reboot in my droplet, but still it seems hothing has changed.

Thank you so much for taking care.

4 Answers

Hi @Areku,

Can you provide us with the relevant Nginx configuration? Did you add the gzip compression to your conf?

Additionally, what’s the exact command you are using to check your files. Is it

curl -H "Accept-Encoding: gzip" -I http://localhost/test.js

Kind regards,
Kalin D.

@KFerdinandov

It is a beautiful morning here. I wish these vibrations reach you wherever you may be :)

Yes, i gave:

sudo nano /etc/nginx/nginx.conf

Made the changes and it looks like this:

        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        gzip_vary on;
        gzip_proxied any;
        gzip_comp_level 6;
        gzip_buffers 16 8k;
        gzip_http_version 1.1;
        gzip_min_length 256;
        gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontob$fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;

Then i gave:

curl -H "Accept-Encoding: gzip" -I http://localhost/test.jpg

And i got:

HTTP/1.1 301 Moved Permanently
Server: nginx/1.10.3 (Ubuntu)
Date: Wed, 04 Sep 2019 18:12:38 GMT
Content-Type: text/html
Content-Length: 194
Connection: keep-alive
Location: https://radha.org.br/test.jpg

I tried this one too:

curl -H "Accept-Encoding: gzip" -I http://arun.com.br/test.jpg

And with the latest command i got:

HTTP/1.1 301 Moved Permanently
Server: nginx/1.10.3 (Ubuntu)
Date: Wed, 04 Sep 2019 18:16:23 GMT
Content-Type: text/html
Content-Length: 194
Connection: keep-alive
Location: https://arun.com.br/test.jpg

Thank you so much.

OMMMMMMM

@KFerdinandov

Cambio… thanks

Hi, guys! Resolved!

With this code from Hummingbird:

# Enable Gzip compression
gzip          on;

# Compression level (1-9)
gzip_comp_level     5;

# Don't compress anything under 256 bytes
gzip_min_length     256;

# Compress output of these MIME-types
gzip_types
    application/atom+xml
    application/javascript
    application/json
    application/rss+xml
    application/vnd.ms-fontobject
    application/x-font-ttf
    application/x-font-opentype
    application/x-font-truetype
    application/x-javascript
    application/x-web-app-manifest+json
    application/xhtml+xml
    application/xml
    font/eot
    font/opentype
    font/otf
    image/svg+xml
    image/x-icon
    image/vnd.microsoft.icon
    text/css
    text/plain
    text/javascript
    text/x-component;

# Disable gzip for bad browsers
gzip_disable  "MSIE [1-6]\.(?!.*SV1)";
Have another answer? Share your knowledge.