命令记不住

登陆

nginx 的 location 和 proxy_pass 是否带斜杠的区别

nginx的location和proxy_pass是否带斜杠的区别

1.proxy_pass最后待斜杠和不带斜杠的区别如下:

location /txffc {
proxy_pass http://localhost:8082;
}

访问URL=http://192.168.231.128/txffc/common,指向的地址实际是:http://localhost:8082/txffc/common,即nginx会把包括匹配到的内容都追加到proxy_pass地址后面。

location /txffc {
proxy_pass http://localhost:8082/;

}

访问URL=http://192.168.231.128/txffc/common,指向的地址实际是:http://localhost:8082/common,即nginx不会把匹配到的内容追加到proxy_pass地址后面。

2.location 最后待斜杠和不带斜杠的区别如下:

location /txffc {
proxy_pass http://localhost:8082;

}

不带斜杠,可以匹配

http://192.168.231.128/txffc/common

http://192.168.231.128/txffcddd

http://192.168.231.128/txffcddd/aabc

location /txffc/ {
proxy_pass http://localhost:8082;

}

带斜杠,可以匹配

http://192.168.231.128/txffc/common

http://192.168.231.128/txffc/aabb

不能匹配

http://192.168.231.128/txffcddd

推荐阅读