首页 > 其他 > 详细

nginx proxy_pass指令 uri以 "/" 结尾和不以 "/" 结尾的区别

时间:2021-02-06 18:35:17      阅读:48      评论:0      收藏:0      [点我收藏+]

 

当location uri为正则匹配(即 location ~ | ~* uri)时,proxy_pass中的url末尾是不允许有 "/" 的

 

一、proxy_pass指令 uri 不以 "/" 结尾

location /test {
   proxy_pass http://192.168.99.10:99;
}

访问地址:本机IP:port/test
实际地址:http://192.168.99.10:99/test
test是一个普通文件且在192.168.99.10主机上必须存在


location /test/ {
   proxy_pass http://192.168.99.10:99;
}

访问地址:本机IP:port/test/xxx
实际地址:http://192.168.99.10:99/test/xxx
test是一个目录且/test/xxx在192.168.99.10主机上必须存在
xxx为任意普通文件


location /test {
   proxy_pass http://192.168.99.10:99/server;
}
访问地址:本机IP:port/test
实际地址:http://192.168.99.10:99/server/test
test是一个普通文件且/server/test在192.168.99.10主机上必须存在

location /test/ {
   proxy_pass http://192.168.99.10:99/server;
}
访问地址:本机IP:port/test/xxx
实际地址:http://192.168.99.10:99/server/test/xxx
test是一个目录且/server/test/xxx在192.168.99.10主机上必须存在
xxx为任意普通文件

 

二、proxy_pass指令 uri 以 "/" 结尾

location /test {
   proxy_pass http://192.168.99.10:99/;
}

访问地址:本机IP:port/test
实际地址:http://192.168.99.10:99/index.html
test在本机和192.168.99.10不一定存在

location /test/ {
   proxy_pass http://192.168.99.10:99/;
}

访问地址:本机IP:port/test/
实际地址:http://192.168.99.10:99/index.html
test在本机和192.168.99.10不一定存在


location /test {
   proxy_pass http://192.168.99.10:99/server/;
}

访问地址:本机IP:port/test
实际地址:http://192.168.99.10:99/server/index.html
test在本机和192.168.99.10不一定存在,但是server/在192.168.99.10一定存在

location /test/ {
   proxy_pass http://192.168.99.10:99/server/;
}

访问地址:本机IP:port/test/
实际地址:http://192.168.99.10:99/server/index.html
test在本机和192.168.99.10不一定存在,但是server/在192.168.99.10一定存在

 

nginx proxy_pass指令 uri以 "/" 结尾和不以 "/" 结尾的区别

原文:https://www.cnblogs.com/gudanaimei/p/14381993.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!