nginx中proxy_pass的斜杠详细说明
一、proxy_pass 后面有 /
location /api/ {
proxy_pass http://localhost:8080/;
}
location /api/ {
proxy_pass http://localhost:8080/xx/;
}
比如请求 http://localhost/api/123 经过处理后实际请求地址是 http://localhost:8080/xx/123
location /api {
proxy_pass http://localhost:8080/xx/;
}
比如请求 http://localhost/api/123 经过处理后实际请求地址是 http://localhost:8080/xx//123 注意变成 //123
总结:如果带/ 把匹配规则(/api/或者/api) 后面得内容直接拼接到 proxy_pass地址后面
二、proxy_pass 后面没有 / location /api/ { proxy_pass http://localhost:8080; } location /api/ { proxy_pass http://localhost:8080; } 比如请求 http://localhost/api/123 经过处理后实际请求地址是 http://localhost:8080/api/123
location /api {
proxy_pass http://localhost:8080;
}
比如请求 http://localhost/api/123 经过处理后实际请求地址是 http://localhost:8080/api/123
总结:如果不带/ 把匹配规则(/api/或者/api) 和匹配规则后面得内容直接拼接到 proxy_pass地址后面
人生的成功不在于拿到一副好牌,而是怎样将坏牌打好。

浙公网安备 33010602011771号