nginx proxy_pass 指令

102 阅读1分钟

在 Nginx 中使用 proxy_pass 指令时,如果在指令结尾使用了 /,则 Nginx 不会自动拼接代理前缀路径。例如,对于以下配置:

location /workflow/static/ {
    proxy_pass http://192.168.0.190:5432/;
}

如果你访问 https://apex-soft.cn/workflow/static/path/to/file,Nginx 会将请求代理到 http://192.168.0.190:5432/path/to/file,即会将请求路径直接代理到目标地址的路径下。

如果在 proxy_pass 的末尾没有使用 /,例如:

location /workflow/static/ {
    proxy_pass http://192.168.0.190:5432;
}

那么 Nginx 会将请求路径追加到目标地址后面。举例来说,访问 https://apex-soft.cn/workflow/static/path/to/file 将会被代理到 http://192.168.0.190:5432/workflow/static/path/to/file

因此,根据你的需求选择是否在 proxy_pass 的末尾使用 /,以便正确处理代理路径。