主要是配置proxy_pass时,斜杠对结果的影响
比如说,我们的前端服务访问地址是:
http://localhost:8080/sthapi/test/home/page
,目的是根据关键词sthapi
实现代理转发到后台接口
1. location、proxy_pass都不加斜杠
location /sthapi {
proxy_pass http://192.168.0.1:13314;
}
实际访问代理地址:http://192.168.0.1:13314/sthapi/test/home/page
2. location加斜杠,proxy_pass不加斜杠
location /sthapi/ {
proxy_pass http://192.168.0.1:13314;
}
实际访问代理地址:http://192.168.0.1:13314/sthapi/test/home/page
3. location不加斜杠,proxy_pass加斜杠
location /sthapi {
proxy_pass http://192.168.0.1:13314/;
}
实际访问代理地址:http://192.168.0.1:13314//test/home/page
4. location、proxy_pass都加斜杠
location /sthapi/ {
proxy_pass http://192.168.0.1:13314/;
}
实际访问代理地址:http://192.168.0.1:13314/test/home/page
5. location不加斜杠,proxy_pass加"sthapi"
location /sthapi {
proxy_pass http://192.168.0.1:13314/sthapi;
}
实际访问代理地址:http://192.168.0.1:13314/sthapi/test/home/page
6. location加斜杠,proxy_pass加"sthapi"
location /sthapi/ {
proxy_pass http://192.168.0.1:13314/sthapi;
}
实际访问代理地址:http://192.168.0.1:13314/sthapitest/home/page
7. location不加斜杠,proxy_pass加"sthapi/"
location /sthapi {
proxy_pass http://192.168.0.1:13314/sthapi/;
}
实际访问代理地址:http://192.168.0.1:13314/sthapi//test/home/page
8. location加斜杠,proxy_pass加"sthapi/"
location /sthapi/ {
proxy_pass http://192.168.0.1:13314/sthapi/;
}
实际访问代理地址:http://192.168.0.1:13314/sthapi/test/home/page