返回博客首页

Nginx 中 proxy_pass 末尾斜杠 `/` 的说明

XiaoNiu · 2026/5/29 06:44:20
nginx

末尾不带 /

当末尾不带 / 的情况,保留原始路径。

如下:

location /api/ {
  proxy_pass http://localhost:8080
}

当访问 /api/user 接口时,会转发到 http://localhost:8080/api/user

末尾带 /

当末尾带 / 的情况,替换原始路径。

如下:

location /api/ {
  proxy_pass http://localhost:8080/
}

当访问 /api/user 接口时,会转发到 http://localhost:8080/user