location /test/ {
proxy_pass http://192.168.2.96:8087/;
}
访问:http://127.0.0.1/test
重定向到: http://127.0.0.1/test/
访问:http://127.0.0.1/test/
http://192.168.2.96:8087/
访问:http://127.0.0.1/test/login
http://192.168.2.96:8087/login
/
(斜杠)的区别location /test {
proxy_pass http://192.168.2.96:8087;
}
访问:http://127.0.0.1/test
http://192.168.2.96:8087/test
访问: http://127.0.0.1/test/
http://192.168.2.96:8087/test/
访问:http://127.0.0.1/test/login
http://192.168.2.96:8087/test/login
location /test{
proxy_pass http://192.168.2.96:8087/define;
}
访问:http://127.0.0.1/test
http://192.168.2.96:8087/define
访问:http://127.0.0.1/test/
http://192.168.2.96:8087/define/
访问:http://127.0.0.1/test/login
http://192.168.2.96:8087/define/login
location /test/ {
proxy_pass http://192.168.2.96:8087;
}
访问:http://127.0.0.1/test
重定向到:http://192.168.2.96/test/
访问:http://127.0.0.1/test/
http://192.168.2.96:8087/test/
访问:http://127.0.0.1/test/login
http://192.168.2.96:8087/test/login
location /test/ {
proxy_pass http://192.168.2.96:8087/define;
}
访问:http://127.0.0.1/test
重定向到http://192.168.2.96/test/
访问:http://127.0.0.1/test/
http://192.168.2.96:8087/define
访问:http://127.0.0.1/test/login
#define与login之间不会有/ ,会直接拼接起来
http://192.168.2.96:8087/definelogin
location /test{
proxy_pass http://192.168.2.96:8087/;
}
访问:http://127.0.0.1/test
http://192.168.2.96:8087/
访问:http://127.0.0.1/test/
http://192.168.2.96:8087//
访问:http://127.0.0.1/test/login
http://192.168.2.96:8087//login
location /test {
proxy_pass http://192.168.2.96:8087/define/;
}
访问:http://127.0.0.1/test
http://192.168.2.96:8087/define/
访问:http://127.0.0.1/test/
http://192.168.2.96:8087/define//
访问:http://127.0.0.1/test/login
http://192.168.2.96:8087/define//login
location /test/ {
proxy_pass http://192.168.2.96:8087/define/;
}
访问:http://127.0.0.1/test
重定向到: http://127.0.0.1/test/
访问:http://127.0.0.1/test/
http://192.168.2.96:8087/define/
访问:http://127.0.0.1/test/login
http://192.168.2.96:8087/define/login
1、proxy_pass
后的URL符合 protocol://ip:port
同时结尾不加/
,则nginx会代理匹配路径部分,否则不代理匹配路径,同时自动添加不匹配路径”部分”,比如/test/login的/login部分
1、https://blog.csdn.net/shichen501/article/details/81003099