proxy_pass路径设置分为以下四种情况:
1. 只有地址
location /api/ {
proxy_pass http://127.0.0.1;
}
外网访问:http://www.test.com/api/anything
等同于访问:http://127.0.0.1/api/anything
2. 地址 + 末尾“/”
location /api/ {
proxy_pass http://127.0.0.1/;
}
外网访问:http://www.test.com/api/anything
等同于访问:http://127.0.0.1/anything
3. 地址 + 其他路径
location /api/ {
proxy_pass http://127.0.0.1/path;
}
外网访问:http://www.test.com/api/anything
等同于访问:http://127.0.0.1/pathanything
4. 地址 + 其他路径 + 末尾“/”
location /api/ {
proxy_pass http://127.0.0.1/path/;
}
外网访问:http://www.test.com/api/anything
等同于访问:http://127.0.0.1/path/anything