1 root与alias
1.1 root
如下配置
:
location /static {
root /opt/module/web
}
1 用户请求服务器路径为 url:port/static/img/test.jpg
2 服务器返回资源路径为 /opt/module/web/static/img/test.jpg
3 总结来说,root的处理结果是 root路径
+ location路径
4 结束可以不用 /
1.2 alias
如下配置
:
location /static {
root /opt/module/web/static/
}
1 用户请求服务器路径为 url:port/static/img/test.jpg
2 服务器返回资源路径为 /opt/module/web/static/img/test.jpg
3 总结来说,alias的处理结果是 alias路径
替换 location路径
4 结束必须要用 /
2 location匹配规则
2.1 空格
默认匹配,普通匹配
location / {
root /opt/module/;
}
2.2 =
精确匹配
location = /static/img/test.png {
root /opt/module/;
}
2.3 ~*
匹配正则表达式,不区分大小写
#符合图片的显示
location ~ \.(GIF|jpg|png|jpeg) {
root /opt/module/;
}
2.4 ~
匹配正则表达式,区分大小写
#GIF必须大写才能匹配到
location ~ \.(GIF|jpg|png|jpeg) {
root /opt/module/;
}
2.5 ^~
以某个字符路径开头
location ^~ /static/img {
root /opt/module;
}
3 Gzip常用配置
# 开启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 相关信息
- 博文不易,辛苦各位猿友点个关注和赞,感谢