Gzip not compressing

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Gzip not compressing

Anand Arun

Hi, guys

I have an issue in nginx ubuntu 16.04 in digital ocean.
It seems i configued everything fine in my nginx.conf, but still the compression does not happen.

Here is the situation posted in DO community.
https://www.digitalocean.com/community/questions/enabling-gzip-compression-guidance-needed

Thanks for any help.



Arun
(61) 99636 1290 - WhatsApp
Instagram: arunviolaocosmico

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

RE: Gzip not compressing

Reinis Rozitis
> Here is the situation posted in DO community.
> https://www.digitalocean.com/community/questions/enabling-gzip-compression-guidance-needed
> Thanks for any help.

Well you are testing in a wrong way. First of all:

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

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
Location: https://radha.org.br/test.jpg

You see that the request is actually redirect (301) and curl doesn't follow it (it's the same with your second attempt).


Also even the response wasn't a redirect it's less than the configured minimal object size for compression (there is generally no sense compressing small objects as you waste more cpu than save traffic. I would suggest increasing it to at least 1Kb):

gzip_min_length 256;


At last while the content type of particular request is text/html if there was an actual jpg image returned then because of the:

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;


.. directive nginx wouldn't compress the file (as there is no 'image/jpeg' included). Besides it doesn't make sense to gzip jpeg as the image format is already compressed.


Hope that helps.

rr



_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
xrd
Reply | Threaded
Open this post in threaded view
|

Re: RE: Gzip not compressing

xrd
Hi, Reinis

I am trying to reduce transfer size in my website. Although i apparently
have enabled Gzip compression, i does not show as enabled in GTmetrix
testing.

Would you, please, be so patient to give me precise instructions on how to
set my Gzip compression properly, writing the code i am to paste in the
config page or any other step i need to proceed to get this done?

I thank you so much for your generousity and attention.


Arun
arun.com.br

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,285576,285578#msg-285578

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

RE: RE: Gzip not compressing

Reinis Rozitis
> I am trying to reduce transfer size in my website. Although i apparently have
> enabled Gzip compression, i does not show as enabled in GTmetrix testing.

For testing purposes just putting:

gzip  on;
gzip_types        text/html text/plain text/xml text/css application/javascript application/json;

in http {} block (and reloading nginx) should be enough to enable gzip (obviously add whatever other types you need like svg / fonts).

Other directives can be specified later for finetuning.


> i does not show as enabled in GTmetrix testing.

You should check which resources the testing tool expects to be compressed (maybe all of those come from external sites?).

Also not all of the recommendations are (very) important.
For example the testing tool for one of my site complains - manifest.json could save 92B (32% reduction). While the 32% percentage looks reasonable the actual gain of 92 bytes doesn't make much sense to compress the file on server side / decompress on client side.

rr

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
xrd
Reply | Threaded
Open this post in threaded view
|

Re: RE: RE: Gzip not compressing

xrd
Hi, RR

Thank you so much for giving attention.

My conf page gzip section 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;


"

When i add your suggestion:


"

gzip on;
gzip_types text/html text/plain text/xml text/css application/javascript
application/json;


"

Should I delete any other line?


Then you also mention:

"

in http {} block (and reloading nginx) should be enough to enable gzip
(obviously add whatever other types you need like svg / fonts).


"

I am not sure what to do with this

"

http {} block.

"

I know that after making changes i should always give

"

sudo nginx -t
sudo systemctl restart nginx

"


Thank you once again :)

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,285576,285580#msg-285580

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
xrd
Reply | Threaded
Open this post in threaded view
|

Re: Gzip not compressing

xrd
In reply to this post by Anand Arun
Hi, guys!!

Resolved!! Thank you!!



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)";

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,285576,285620#msg-285620

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx