【发布时间】:2021-12-01 12:28:59
【问题描述】:
如何将 Envoy 配置为公共 Internet 服务的代理,以便每条路径都可以路由到不同的服务?例如:
http://foo.example.com/service1/* -> http://somewhere.com/*
http://foo.example.com/service2/* -> http://somewhereelse.com/*
【问题讨论】:
标签: envoyproxy
如何将 Envoy 配置为公共 Internet 服务的代理,以便每条路径都可以路由到不同的服务?例如:
http://foo.example.com/service1/* -> http://somewhere.com/*
http://foo.example.com/service2/* -> http://somewhereelse.com/*
【问题讨论】:
标签: envoyproxy
假设您的 envoy 代理可通过 http://foo.example.com 访问,您可以使用如下配置:
static_resources:
listeners:
- address:
socket_address:
address: 0.0.0.0
port_value: 80
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
codec_type: AUTO
stat_prefix: ingress_http
route_config:
name: local_route
virtual_hosts:
- name: backend
domains:
- "*"
routes:
- match:
prefix: "/service1"
route:
prefix_rewrite: "/"
cluster: service1
auto_host_rewrite: true
- match:
prefix: "/service2"
route:
prefix_rewrite: "/"
cluster: service2
auto_host_rewrite: true
http_filters:
- name: envoy.filters.http.router
clusters:
- name: service1
connect_timeout: 15s
type: LOGICAL_DNS
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: service1
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: somewhere.com
port_value: 80
- name: service2
connect_timeout: 15s
type: LOGICAL_DNS
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: service2
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: somewhereelse.com
port_value: 80
重要的部分是:
prefix_rewrite: "/" 将http://foo.example.com/service1/stuff 改写为http://somewhere.com/stuff(其实就是去掉/service1)auto_host_rewrite: true 在转发过程中添加Host 标头(集群上游主机的主机名)【讨论】: