栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

nginx中资源配置参数

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

nginx中资源配置参数

1 root和alias

注意:root则是最上层目录的定义,alias是一个目录别名的定义。

1.1 alias用法

映射路径是对上层路径的替换。

location /img/ {
    alias /home/static/img/;
}

当请求“/img/test.png”时,映射地址为”/home/static/img/test.png“=“/home/static/img/”+“test.png”。

location /img {
    alias /home/static/img;
}

当请求“/img/test.png”时,映射地址为”/home/static/img/test.png“=“/home/static/img”+“/test.png”。

1.2 root用法

映射路径是对上层路径的拼接。

# 下面的结果跟上面的结果一样
location /img/ {
    root /home/static/img/;
}

当请求“/img/test.png”时,映射地址为”/home/static/img//img/test.png“=“/home/static/img/”+“/img/test.png”,注意此处的”//“nginx应该做了处理,请求时对请求结果没有影响。

location /img {
    root /home/static/img;
}

当请求“/img/test.png”时,映射地址为”/home/static/img/img/test.png“=“/home/static/img”+“/img/test.png”。

2 proxy_pass的斜杠

proxy_pass的”/“对资源请求影响很大。

2.1 资源替换

只要”http://192.168.2.10:5000“含有URI(包括/),就属于资源替换。

location /api/ {
    alias http://192.168.2.10:5000/api/;
}

当请求是"http://localhost/api/index"时,http://localhost/api/替换为http://192.168.2.10:5000/api,代理地址是“http://192.168.2.10:5000/api/index”=“http://192.168.2.10:5000/api/”+“index”。

location /api/ {
    alias http://192.168.2.10:5000/;
}

当请求是"http://localhost/api/index"时,,http://localhost/api/替换为http://192.168.2.10:5000/,代理地址是“http://192.168.2.10:5000/index”=“http://192.168.2.10:5000/”+“index”。

location /api {
    alias http://192.168.2.10:5000/;
}

当请求是"http://localhost/api/index"时,http://localhost/api替换为http://192.168.2.10:5000/,代理地址是“http://192.168.2.10:5000/index”=“http://192.168.2.10:5000/”+“/index”。注意,此处还有“//”。

location /api/ {
    alias http://192.168.2.10:5000/api;
}

当请求是"http://localhost/api/index"时,"http://localhost/api/“替换为"http://192.168.2.10:5000/api”,代理地址是“http://192.168.2.10:5000/apiindex”=“http://192.168.2.10:5000/api”+“index”。

2.2 资源拼接

只要"http://192.168.2.10:5000"后面不含有URI,就是属于资源拼接。

location /api {
    alias http://192.168.2.10:5000;
}

当请求是"http://localhost/api/index"时,代理地址是“http://192.168.2.10:5000/api/index”=“http://192.168.2.10:5000”+“/api/index”。

location /api/ {
    alias http://192.168.2.10:5000;
}

当请求是"http://localhost/api/index"时,代理地址是“http://192.168.2.10:5000/api/index”=“http://192.168.2.10:5000”+“/api/index”。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/974000.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号