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

 

当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一定存在

 

posted @ 2021-02-06 17:05  junffzhou  阅读(786)  评论(0编辑  收藏  举报