nginx 反向代理中反斜杠与代理路径的映射关系
nginx 中 location 和 proxy_pass 中最后是否存在反斜杠,会对最终服务器收到的请求路径产生影响。
| 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 |
| 5 | /foo/ | http://192.168.1.48/bar/ | /bar/api |
| 6 | /foo | http://192.168.1.48/bar/ | /bar//api |
| 7 | /foo/ | http://192.168.1.48/bar | /barapi |
| 8 | /foo | http://192.168.1.48/bar | /bar/api |
proxy_pass 在主机名和端口后面未跟随任何字符串时会将请求的路径全部带入,在后面跟随字符串的情况下会将location中的路径从请求路径中删除后进行处理。
原文链接地址:https://blog.exsvc.cn/article/nginx-reverse-path.html
转载请注明:转载自 易科博客 ,谢谢!