nginx中location与proxy_pass的斜杠问题
proxy_pass类型
不带URI,只包含IP和端口:proxy_pass http://192.168.200.227:8080
带URI(包括单斜杠):proxy_pass http://192.168.200.227:8080/
,
proxy_pass http://192.168.200.227:8080/aaa
,proxy_pass http://192.168.200.227:8080/aaa/
等情况
配置例子
- 不带URI,只包含IP和端口,将所有URI拼入proxy_pass后面
1 2 3 4 5 6 7 8 9 10 11
| # 访问地址:http://192.168.200.227:80/proxy/api/test
location /proxy/ { proxy_pass http://192.168.200.227:8080; } # 1️⃣ 实际地址:http://192.168.200.227:8080/proxy/api/test
location /proxy { proxy_pass http://192.168.200.227:8080; } # 2️⃣ 实际地址:http://192.168.200.227:8080/proxy/api/test
|
- 带URI(包括单斜杠),将排除location后的URI拼入proxy_pass后面
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| # 访问地址:http://192.168.200.227:80/proxy/api/test
location /proxy/ { proxy_pass http://192.168.200.227:8080/; } # 3️⃣ 实际地址:http://192.168.200.227:8080/api/test
location /proxy { proxy_pass http://192.168.200.227:8080/; } # 4️⃣ 实际地址:http://192.168.200.227:8080//api/test
location /proxy/ { proxy_pass http://192.168.200.227:8080/test/; } # 5️⃣ 实际地址:http://192.168.200.227:8080/test/api/test
location /proxy { proxy_pass http://192.168.200.227:8080/test/; } # 6️⃣ 实际地址:http://192.168.200.227:8080/test//api/test
location /proxy/ { proxy_pass http://192.168.200.227:8080/test; } # 7️⃣ 实际地址:http://192.168.200.227:8080/testapi/test
location /proxy { proxy_pass http://192.168.200.227:8080/test; } # 8️⃣ 实际地址:http://192.168.200.227:8080/test/api/test
|