首页 > 其他分享 >location匹配带参数和不带参数

location匹配带参数和不带参数

时间:2023-02-21 11:22:17浏览次数:33  
标签:不带 http 9099 123 参数 location pass proxy

1、location后面带 / ,proxy_pass 后面不带 /

location /aaa/{
    proxy_pass http://127.0.0.1:9099/test4/hello/getProxyUrl;
}

 

测试地址:http://localhost:10000/aaa/123

 测试结果:请求失败!

实际地址 http://127.0.0.1:9099/test4/hello/getProxyUrl123,参数123直接拼接放在了最后,且没有 / ,导致请求失败

 

 2、location后面带 / ,proxy_pass 后面带 /

 

 测试结果:成功!实际地址为:http://127.0.0.1:9099/test4/hello/getProxyUrl/123,参数123拼接在了最后

 

3、location后面不带 / ,proxy_pass 后面带 /

location /aaa{
    proxy_pass http://127.0.0.1:9099/test4/hello/getProxyUrl/;
}

 

 

 

测试结果:成功!实际地址为:http://127.0.0.1:9099/test4/hello/getProxyUrl//123,参数123拼接在了最后,且多了个 /

 

4、location后面不带 / ,proxy_pass 后面不带 /

location /aaa{
    proxy_pass http://127.0.0.1:9099/test4/hello/getProxyUrl;
}

 

 测试结果:成功!实际地址为:http://127.0.0.1:9099/test4/hello/getProxyUrl/123,参数123拼接在了最后

 

总结:location、proxy_pass最好都带 / ,或者都不带 /;

  区别:location带 / 匹配更精准,像 /aaaBBB 这种是不会匹配的;location不带 / ,像 /aaaBBB 这种是会匹配的。location带与不带 / 看实际需求。

 Tip:  多个location规则优先匹配最长字符串的

标签:不带,http,9099,123,参数,location,pass,proxy
From: https://www.cnblogs.com/bobobjh/p/17139933.html

相关文章