比如请求 /a/b.html
location /a {
proxy_pass http://server;
}
实际代理的目标url是http://server/a/b.html (把/a/b.html拼接到http://server之后)
location /a/ {
proxy_pass http://server/;
}
location | proxy_pass | 代理路径 |
---|---|---|
/api/ | http://server:8080 | http://server:8080/api/user/list |
/api/ | http://server:8080/ | http://server:8080/user/list |
/api | http://server:8080 | http://server:8080/api/user/list |
/api | http://server:8080/ | http://server:8080/user/list |
location | proxy_pass | 代理路径 |
---|---|---|
/api/ | http://server:8080/gw | http://server:8080/gwuser/list |
/api/ | http://server:8080/gw/ | http://server:8080/gw/user/list |
/api | http://server:8080/gw | http://server:8080/gw/user/list |
/api | http://server:8080/gw/ | http://server:8080/gw/user/list |
以服务地址http://127.0.0.1:5053/api/test/list进行说明,访问地址是http://127.0.0.1/api/test/list。location后斜杆与proxy_pass后斜杆问题如下:
location /api {
proxy_pass http://127.0.0.1:5053;
}
location /api/ {
proxy_pass http://127.0.0.1:5053;
}
location /api {
proxy_pass http://127.0.0.1:5053/;
}
location /api/ {
proxy_pass http://127.0.0.1:5053/;
}
location /api {
proxy_pass http://127.0.0.1:5053/api;
}
location /api/ {
proxy_pass http://127.0.0.1:5053/api;
}
location /api {
proxy_pass http://127.0.0.1:5053/api/;
}
location /api/ {
proxy_pass http://127.0.0.1:5053/api/;
}