1

conf

gzip  on;
gzip_vary  on;
gzip_min_length  100;
gzip_buffers  16 8k;
gzip_proxied  any;
gzip_types
    text/plain
    text/css
    text/javascript
    application/json
    application/javascript;

enter image description here

3
  • 2
    Do not post images of code or errors! Images and screenshots can be a nice addition to a post, but please make sure the post is still clear and useful without them. If you post images of code or error messages make sure you also copy and paste or type the actual code/message into the post directly. – Rob Jul 22 '18 at 11:06
  • Also, try to specify your infrastructure: linux distribution, distribution version, nginx version, virtual hosts configuration, other relevant data. – Leo Jul 25 '18 at 2:28
  • Please post the complete output of nginx -T. – Michael Hampton Jul 27 '18 at 13:22
1

Make Sure Gzip module installed with nginx

2>&1 nginx -V | tr -- - '\n' | grep _module | grep gzip

Output Should be : http_gzip_static_module

Configuration

Host Configuration file under server block.

gzip on;
gzip_disable "msie6";

gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
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/javascript;

service nginx reload

Testing

curl -H "Accept-Encoding: gzip" -I https://example.com/
1

Have you tried to add 'gzip_comp_level level;'? It looks like you missed something in your configuration. Here you have a working example:

gzip on;
gzip_comp_level 2;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_types text/plain text/html text/css application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_disable "MSIE [1-6].(?!.*SV1)";
gzip_vary on;
2
  • have added gzip_comp_level 2; but still not working – clarkk Jul 25 '18 at 20:33
  • Quite strange. Have you tried to use example configuration provided by me? Please backup your config, paste my example, restart the service and check if it works. – dave Jul 26 '18 at 9:43
0

In my experience you can't rely on browser developer console output to check for gzip compression.

Any anti virus software you have running is probably going to intercept and decompress the gzip files to scan them before they hit the browser.

I have gzip enabled on my Nginx servers and I see no evidence of it in my chrome dev console.

curl reveals the truth though...

curl -H "Accept-Encoding: gzip" -I https://example.com/

returns:

HTTP/1.1 200 OK
Server: nginx
Date: Sun, 22 Jul 2018 16:22:41 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding
Link: <https://example.com/>; rel=shortlink
Access-Control-Allow-Origin: https://example.com
Content-Encoding: gzip

Where Content-Encoding: gzip is obviously what you are looking for in your response headers.

You may also want to add a gzip_http_version 1.0; directive to your Nginx conf, as by default http 1.1 is minimum version required for Nginx to serve gzip

3
  • your command line still returns Content-Type: text/html; charset=utf-8 in my case – clarkk Jul 25 '18 at 20:34
  • Content encoding is the relevant header, not content type – miknik Jul 25 '18 at 20:50
  • There is no such header in the response – clarkk Jul 27 '18 at 7:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.