Nginx gzip compress server contents not working

This is part of my nginx.conf, but I'm not sure why when I check with the gzip parser or the http header, the content is not compressed.

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;


}

Can I find out what the problem is?

+5
source share
3 answers

Across

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

you have disabled gzip for almost any browser that has User-Agent numbers in it, since 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 more details .

+8
source

, , http://nginx.org/en/docs/http/ngx_http_gzip_module.html#gzip_types , gzip_types , text/html. /html gzip_types . , , , .

, ,

server {...}  

?

, - /etc/nginx/conf.d/*.conf, "gzip off"?

+2

The standard Nginx configuration (at least v1.4.6) has a gzip_typesline commented out. You need to uncomment it so that the listed resource types are compressed.

0
source

All Articles