我在Nginx
下运行多个服务。所有这些服务都在不同的端口上。
如何根据初始base URI
将请求重定向到特定服务?
例如为URL https://my-domain/serviceA/v1/schema
将8181
作为/v1/schema
和https://my-domain/serviceB/v1/api/schema
移植到9191
作为/v1/api/schema
。
到目前为止,我已经能够使用location
将请求转发到基于初始路径的特定端口,但无法从/serviceA
中删除/serviceB
或URI
。
proxy_pass
语句可以包含可选的URI组件。有关详细信息,请参阅this document。
例如:
location /serviceA/ {
proxy_pass http://192.168.0.2:8080/;
...
}
URI组件是/
语句中的最终proxy_pass
。 URI /serviceA/foo
在传递上游之前被转换为/foo
。在/
值上使用尾随的location
进行正确的翻译。