Nginx中proxy_pass末尾带斜杠/和不带的区别

总结:
如果proxy_pass末尾有斜杠/,proxy_pass不拼接location的路径
如果proxy_pass末尾无斜杠/,proxy_pass会拼接location的路径
一、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

猜你喜欢

转载自blog.csdn.net/wondermaomao/article/details/127664829
今日推荐