nginx的proxy_pass分为两种类型
- 不带url方式 例
http://localhost:8080 - 带url方式 例
http://localhost:8080/http://localhost:8080/aaahttp://localhost:8080/aa/bb
具体处理方式
对于不带url方式 nginx将会保留location中路径部分 也就是将nginx接收到的访问路径 原样反代过去
location /api1/ {
proxy_pass http://localhost:8080;
}访问http://localhost/api1 反代到http://localhost:8080/api1
访问http://localhost/api1/xxxx 反代到http://localhost:8080/api1/xxx
对于带url方式 nginx会将除了location的路径部分 放到反代的地址后面
location /api1/ {
proxy_pass http://localhost:8080/;
}访问http://localhost/api1 反代到http://localhost:8080/
访问http://localhost/api1/xxxx 反代到http://localhost:8080/xxx
location /api1/ {
proxy_pass http://localhost:8080/aa;
}访问http://localhost/api1 反代到http://localhost:8080/aa
访问http://localhost/api1/xxxx 反代到http://localhost:8080/aaxxxx
location /api1/ {
proxy_pass http://localhost:8080/aa/;
}访问http://localhost/api1 反代到http://localhost:8080/aa/
访问http://localhost/api1/xxxx 反代到http://localhost:8080/aa/xxxx
location /api1 {
proxy_pass http://localhost:8080/aa/;
}访问http://localhost/api1 反代到http://localhost:8080/aa/
访问http://localhost/api1/xxxx 反代到http://localhost:8080/aa//xxxx
注意这里的双斜杠 注意分析
例如访问 http://localhost/api1/xxxx
将协议头 域名 端口拿掉还剩余/api1/xxxx
再将location匹配的部分拿掉还剩/xxxx 放到后面 就变成了http://localhost:8080/aa//xxxx
版权属于:本文是原创文章,版权归 吾梦小站 所有。
本文链接:https://nikm.cn/archives/67.html
本站所有原创文章采用 知识共享署名-非商业性使用 4.0 国际许可协议 进行许可。
您可以自由地转载和修改,但请务必注明文章来源并且不可用于商业目的。

