参考博客地址:
(273条消息) Nginx中proxy_pass末尾带斜杠/和不带的区别_lihefei_coder的博客-CSDN博客_proxy_pass /
Nginx中的proxy_pass的斜杠问题总结 - 知乎 (zhihu.com)
最近在是使用nginx配置代理,正好顺便看到其他博主的 博客,认为比较好,所以粘贴记录一下,以免后面使用的时候找不见:
proxy_pass末尾有斜杠
location /api/ {
proxy_pass http://127.0.0.1:8000/;
}
请求地址:http://localhost/api/test
转发地址:http://127.0.0.1:8000/test
proxy_pass末尾无斜杠
location /api/ {
proxy_pass http://127.0.0.1:8000;
}
请求地址:http://localhost/api/test
转发地址:http://127.0.0.1:8000/api/test
proxy_pass包含路径,且末尾有斜杠
location /api/ {
proxy_pass http://127.0.0.1:8000/user/;
}
请求地址:http://localhost/api/test
转发地址:http://127.0.0.1:8000/user/test
proxy_pass包含路径,末尾无斜杠
location /api/ {
proxy_pass http://127.0.0.1:8000/user;
}
请求地址:http://localhost/api/test
转发地址:http://127.0.0.1:8000/usertest
只有IP和端口
测试URL:http://127.0.0.1:80/proxy/api/test
(1)配置
location /proxy/{
proxy_pass http://127.0.0.1:8080;
}
实际地址:http://127.0.0.1:8080/proxy/api/test
(2)配置
location /proxy{
proxy_pass http://127.0.0.1:8080;
}
实际地址:http://127.0.0.1:8080/proxy/api/test
其他情况,端口号之后有其他路径
测试URL:http://127.0.0.1:80/proxy/api/test
(1)配置
location /proxy/{
proxy_pass http://127.0.0.1:8080/;
}
实际地址:http://127.0.0.1:8080/api/test
(2)配置
location /proxy {
proxy_pass http://127.0.0.1:8080/;
}
实际地址:http://127.0.0.1:8080//api/test
(3)配置
location /proxy/{
proxy_pass http://127.0.0.1:8080/test/;
}
实际地址:http://127.0.0.1:8080/test/api/test
(4)配置
location /proxy{
proxy_pass http://127.0.0.1:8080/test/;
}
实际地址:http://127.0.0.1:8080/test//api/test
(5)配置
location /proxy/{
proxy_pass http://127.0.0.1:8080/test;
}
实际地址:http://127.0.0.1:8080/testapi/test
(6)配置
location /proxy {
proxy_pass http://127.0.0.1:8080/test;
}
实际地址:http://127.0.0.1:8080/test/api/test