Nginx 将 /path 重写为 /

问题描述 投票:0回答:1

我在 8080 端口运行服务 A,在 8081 端口运行服务 B。我想设置一个 nginx 代理,所以当我访问 http://localhost/serviceA 时,它将重定向到服务 A,当我访问 http:// localhost/serviceB 它将重定向到服务 B。 服务 A 没有 /serviceA 路径,服务 B 没有路径 /serviceB。两种服务都只有 / 路径。

nginx url-rewriting
1个回答
0
投票

Iry这个:

server {
    location /serviceA {
       proxy_pass http://serviceA:8080/;
    }
    location /serviceB {
       proxy_pass http://serviceB:8081/;
    }
}

有了这个配置,我们有例如:

/serviceA/ -> /
/ServiceA/bla -> /bla
© www.soinside.com 2019 - 2024. All rights reserved.