| 这篇文章主要介绍了浅谈nginx反向代理中神奇的斜线,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧 在进行nginx反向代理配置的时候,location和proxy_pass中的斜线会造成各种困扰,有时候多一个或少一个斜线,就会造成完全不同的结果,VPS云主机所以特地将location和proxy_pass后有无斜线的情况进行了排列组合,进行了一次完整的测试,找出原理,以提高姿势水平~ 〇. 环境信息
 两台nginx服务器 nginx A: 192.168.1.48 nginx B: 192.168.1.56 一. 测试方法
 在nginx A中配置不同的规则,然后请求nginx A: http://192.168.1.48/foo/api
 观察nginx B收到的请求,具体操作是查看日志中的$request字段
 二. 测试过程及结果
 案例1
 nginx A配置:location /foo/ { proxy_pass http://192.168.1.56/;} nginx B收到的请求:/api
 案例2
 nginx A配置:location /foo/ { proxy_pass http://192.168.1.56/;} nginx B收到的请求://api
 案例3
 nginx A配置:location /foo/ { proxy_pass http://192.168.1.56/;} nginx B收到的请求:/foo/api
 案例4
 nginx A配置:location /foo/ { proxy_pass http://192.168.1.56/;} nginx B收到的请求:/foo/api
 案例5
 nginx A配置:location /foo/ { proxy_pass http://192.168.1.56/bar/;} nginx B收到的请求:/bar/api
 案例6
 nginx A配置:location /foo { proxy_pass http://192.168.1.56/bar/;} nginx B收到的请求:/bar//api
 案例7
 nginx A配置:location /foo/ { proxy_pass http://192.168.1.56/bar;} nginx B收到的请求:/barapi 案例8
 nginx A配置:location /foo { proxy_pass http://192.168.1.56/bar;} nginx B收到的请求:/bar/api
 看到这里是不是都晕了呢,其实是有规律的 现在把这些案例按表格排列起来,结果表示nginx B收到的请求 表一 案例 location proxy_pass 结果 1 /foo/ http://192.168.1.48/ /api 2 /foo http://192.168.1.48/ //api 3 /foo/ http://192.168.1.48 /foo/api 4 /foo http://192.168.1.48 /foo/api 
 |