第一组:
location /api/ {
proxy_pass http://127.0.0.1:5000/; # 本文用的有斜杠
}
末尾加了斜杠,那么会重写url里的 /api/ (你定义的 location ),
原来的 ip:8082/api/getxxx -> http://127.0.0.1:5000/getxxx
/api/ 被 / 取代
第二组:
location /api/ {
proxy_pass http://127.0.0.1:5000; #比第一组的末尾少一个斜杠 /
}
末尾不加/,不会重写url
原来的 ip:8082/api/getxxx -> http://127.0.0.1:5000/api/getxxx
第三组:
location /api/ {
proxy_pass http://127.0.0.1:5000/BASE/; #多一个路径
}
原来的 ip:8082/api/getxxx -> http://127.0.0.1:5000/BASE/getxxx
加了 /BASE/,那么 /api/ 被 /BASE/ 重写
第四组
location /api/ {
proxy_pass http://127.0.0.1:5000/BASE; #多一个路径,但少一个斜杠
}
原来的 ip:8082/api/getxxx -> http://127.0.0.1:5000/BASEgetxxx
只加了 /BASE,那么 /api/ 被 /BASE 重写
这种写法尤其要注意!