石家庄网站建设电话,重庆最便宜的网站建设,app公司管理,聊城广告设计公司location路径与proxy_pass匹配规则 路径替换总结当访问地址是 http://127.0.0.1/api/user/list注意:location后斜杆与proxy_pass后斜杆/问题#xff0c;最好要么两者都加斜杆#xff0c;要么都不加 路径替换
配置proxy_pass时#xff0c;可以实现URL路径的部分… location路径与proxy_pass匹配规则 路径替换总结当访问地址是 http://127.0.0.1/api/user/list注意:location后斜杆与proxy_pass后斜杆/问题最好要么两者都加斜杆要么都不加 路径替换
配置proxy_pass时可以实现URL路径的部分替换。proxy_pass的目标地址默认不带/表示只代理域名(ip端口)path和query部分不会变把请求的path和query拼接到proxy_pass目标域名之后作为代理的URL如果在目标地址端口后有‘/’或者‘/xx/yy’等目录则表示把path中location匹配成功的部分剪切掉之后再拼接到proxy_pass目标地址后面
比如请求 /a/b.html
location /a {proxy_pass http://server;
}实际代理的目标url是http://server/a/b.html (把/a/b.html拼接到http://server之后)
location /a/ {proxy_pass http://server/;
}总结
当访问地址是 http://127.0.0.1/api/user/list
若proxy_pass代理地址端口后无任何字符则转发后地址为代理地址访问的path
locationproxy_pass代理路径/api/http://server:8080http://server:8080/api/user/list/api/http://server:8080/http://server:8080/user/list/apihttp://server:8080http://server:8080/api/user/list/apihttp://server:8080/http://server:8080/user/list
若proxy_pass代理地址端口后有目录包括/则转发后地址为代理地址访问的path去除location匹配的路径
locationproxy_pass代理路径/api/http://server:8080/gwhttp://server:8080/gwuser/list/api/http://server:8080/gw/http://server:8080/gw/user/list/apihttp://server:8080/gwhttp://server:8080/gw/user/list/apihttp://server:8080/gw/http://server:8080/gw/user/list
注意:location后斜杆与proxy_pass后斜杆/问题最好要么两者都加斜杆要么都不加
以服务地址http://127.0.0.1:5053/api/test/list进行说明访问地址是http://127.0.0.1/api/test/list。location后斜杆与proxy_pass后斜杆问题如下
location、proxy_pass都不加斜杠实际代理地址http://127.0.0.1:5053/api/test/list
location /api {proxy_pass http://127.0.0.1:5053;
}location加斜杠proxy_pass不加斜杠实际代理地址http://127.0.0.1:5053/api/test/list正确的
location /api/ {proxy_pass http://127.0.0.1:5053;
}location不加斜杠proxy_pass加斜杠实际代理地址http://127.0.0.1:5053//test/list错误的也出现了双斜杠
location /api {proxy_pass http://127.0.0.1:5053/;
}location、proxy_pass都加斜杠实际代理地址http://127.0.0.1:5053/test/list错误的
location /api/ {proxy_pass http://127.0.0.1:5053/;
}location不加斜杠proxy_pass加api实际代理地址http://127.0.0.1:5053/api/test/list正确的
location /api {proxy_pass http://127.0.0.1:5053/api;
}location加斜杠proxy_pass加api实际代理地址http://127.0.0.1:5053/apitest/list错误的少了一个斜杆
location /api/ {proxy_pass http://127.0.0.1:5053/api;
}location不加斜杠proxy_pass加api/实际代理地址http://127.0.0.1:5053/api//test/list出现双斜杠问题后端在认证请求时会校 验失败
location /api {proxy_pass http://127.0.0.1:5053/api/;
}location加斜杠proxy_pass加api/实际代理地址http://127.0.0.1:5053/api/test/list正确的
location /api/ {proxy_pass http://127.0.0.1:5053/api/;
}