Nginx location and Gzip configuration

1 root 与 alias

1.1 root

如下配置

location /static {
root /opt/module/web
}

1 The path of the user request server is url:port/static/img/test.jpg

2 The resource path returned by the server is /opt/module/web/static/img/test.jpg

3 In summary, the result of root processing is root路径+location路径

4 can not be used at the end /

1.2 alias

如下配置

location /static {
root /opt/module/web/static/
}

1 The path of the user request server is url:port/static/img/test.jpg

2 The resource path returned by the server is /opt/module/web/static/img/test.jpg

3 In summary, the results of the processing alias is alias路径replacedlocation路径

4 must be used at the end /

2 location matching rules

2.1 空格Default matching, ordinary matching

location / {
root /opt/module/;
}

2.2 =Exact match

location = /static/img/test.png {
root /opt/module/;
}

2.3 ~*Matching regular expressions, not case sensitive

#符合图片的显示
location ~ \.(GIF|jpg|png|jpeg) {
root /opt/module/;
}

2.4 ~Matching regular expressions, case sensitive

#GIF必须大写才能匹配到
location ~ \.(GIF|jpg|png|jpeg) {
root /opt/module/;
}

2.5 ^~start with a character path

location ^~ /static/img {
root /opt/module;
}

3 Gzip common configuration

# 开启gzip压缩功能,目的:提高传输效率,节约带宽
gzip on;
#限制最小压缩,小于1字节的文件不会压缩
gzip_min_length 1;
# 定义压缩的级别(压缩比,文件越大,压缩越多,但是CUP负载会越高)
gzip_comp_level 3;
# 进行压缩的文件类型
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/bmp application/x-bmp image/x-ms-bmp application/vnd.ms-fontobject font/ttf font/opentype font/x-woff;

4 Related information

  • The blog post is not easy, everyone who has worked so hard to pay attention and praise, thank you

Guess you like

Origin blog.csdn.net/qq_15769939/article/details/113364812
Recommended