理解nginx的proxy_pass用法和url的路径翻译《nginx的proxy_pass代理路径翻译对照表》

曾经沧海难为水,如果是根目录的情况,nginx的以下的代理方式比较简单

location / {
    proxy_pass http://127.0.0.1:8080;
}
location / {
    proxy_pass http://127.0.0.1:8080/;
}

以上两种配置,如果访问/abc/def,真实接收到的访问请求都是 http://127.0.0.1:8080/abc/def

如果是非root的情况:

location /app {
    proxy_pass http://127.0.0.1:8080;
}
和
location /app/ {
    proxy_pass http://127.0.0.1:8080/;
}

其结果则不同,仓促配置的情况下,一个“/”号的位置效果令人抓狂。

由此总结出以下的《nginx的proxy_pass代理路径翻译对照表》:

序号Nginx locationproxy_pass URLTest URLPath received
1/test1http://127.0.0.1:8080/test1/abc/test/test1/abc/test
2/test2http://127.0.0.1:8080//test2/abc/test//abc/test
3/test3/http://127.0.0.1:8080/test3/abc/test/test3/abc/test
4/test4/http://127.0.0.1:8080//test4/abc/test/abc/test
5/test5http://127.0.0.1:8080/app1/test5/abc/test/app1/abc/test
6/test6http://127.0.0.1:8080/app1//test6/abc/test/app1//abc/test
7/test7/http://127.0.0.1:8080/app1/test7/abc/test/app1abc/test
8/test8/http://127.0.0.1:8080/app1//test8/abc/test/app1/abc/test
9/http://127.0.0.1:8080/test9/abc/test/test9/abc/test
10/http://127.0.0.1:8080//test10/abc/test/test10/abc/test
11/http://127.0.0.1:8080/app1/test11/abc/test/app1test11/abc/test
12/http://127.0.0.1:8080/app2//test12/abc/test/app2/test12/abc/test
nginx的proxy_pass代理路径翻译对照表
滚动至顶部