静态资源压缩

 

1)静态资源压缩语法

#开启压缩
Syntax:    gzip on | off;
Default:    gzip off;
Context:    http, server, location, if in location

#指定压缩类型
Syntax:    gzip_types mime-type ...;
Default:    gzip_types text/html;
Context:    http, server, location

#指定压缩比例
Syntax:    gzip_comp_level level;
Default:    gzip_comp_level 3-5;     #1-9个级别
Context:    http, server, location

#指定传输协议
Syntax:    gzip_http_version 1.0 | 1.1;
Default:    gzip_http_version 1.1;
Context:    http, server, location

 

2)压缩配置

[root@web01 /code/cache]# vim /etc/nginx/conf.d/gzip.conf 
server {
    listen 80;
    server_name linux.gzip.com;
    root /code/cache;

    location ~* \.(jpg|png|gif)$ {
        gzip on;
        gzip_types image/jpeg image/gif image/png;
        gzip_comp_level 9;
    }

    location ~* \.(txt|css)$ {
        gzip on;
        gzip_types text/css text/plain;
        gzip_comp_level 5;
    }
}

 

posted @ 2020-09-11 15:33  六月OvO  阅读(111)  评论(0编辑  收藏  举报