Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx server contents gzip compress not working

This is the portion in my nginx.conf but i not sure why when i check with gzip compression checker or http header, the content is not compress.

https://pasify.com

user              nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;

    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  0;
    #keepalive_requests 5;
    #keepalive_timeout  65;
    send_timeout 10m;

    # output compression saves bandwidth
    gzip  on;
    gzip_http_version 1.1;
    gzip_vary on;
    gzip_comp_level 6;
    gzip_proxied any;
    gzip_types text/plain text/html text/css application/json application/javascript application/x-javascript text/javascript text/xml application/xml application/rss+xml application/atom+xml application/rdf+xml;

    gzip_buffers 16 8k;

    # Disable gzip for certain browsers.
    gzip_disable MSIE [1-6].(?!.*SV1);

    # Load config files from the /etc/nginx/conf.d directory
    # The default server is in conf.d/default.conf
    include /etc/nginx/conf.d/*.conf;

    ## Detect when HTTPS is used
    map $scheme $fastcgi_https {
      default off;
      https on;
    }

    client_max_body_size 20M;


}

May i know what is the problem ?

like image 874
1myb Avatar asked Aug 13 '12 07:08

1myb


People also ask

Why is gzip not working?

Older version of Gzip have a file size limit of something like 2GB. Any file larger than that will not be compressed using the Gzip algorithm. That is, however, relying on the older algorithms. Newer versions of Gzip work with larger files, though it can often take a bit of time to compress them and uncompress them.

How do you check GZIP compression is enabled or not?

Double click on the file and select headers. Under 'Response headers' you are looking for the 'Connection-Encoding' field, it will say gzip if it is enabled. NOTE: By default, Deflate is enabled on all of our servers.


2 Answers

By

gzip_disable MSIE [1-6].(?!.*SV1);

you've disabled gzip for almost any browser which has digits in it's User-Agent, as there are two separate regular expressions: "MSIE" and "[1-6].(?!.*SV1)". Add quotes around or better use this instead:

gzip_disable msie6;

See docs for details.

like image 77
Maxim Dounin Avatar answered Sep 28 '22 19:09

Maxim Dounin


the only remark I have is that http://nginx.org/en/docs/http/ngx_http_gzip_module.html#gzip_types says that gzip_types specifies the types to be compressed in addition to text/html. so the text/html in your gzip_types is unnecessary. If specifying it anyway is problematic I'd consider that a bug, but try removing it just to be sure.

if that isn't it can you show us what your

server {...}  

block look like?

also check to make sure that there isn't anything in /etc/nginx/conf.d/*.conf that sets "gzip off"?

like image 32
cobaco Avatar answered Sep 28 '22 20:09

cobaco