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地址后面

 

posted @ 2025-01-09 16:27  .NET_海  阅读(149)  评论(0)    收藏  举报