envoyproxy / envoy

Cloud-native high-performance edge/middle/service proxy
https://www.envoyproxy.io
Apache License 2.0
24.67k stars 4.75k forks source link

How to add a fallback http virtual host #35297

Closed imlk0 closed 1 month ago

imlk0 commented 1 month ago

Title: How to add a fallback http virtual host

Description:

I'm writing a listener that is a dynamic forward proxy (using the envoy.filters.http.dynamic_forward_proxy http filter) that will distribute requests based on the target domain name to two different clusters.

The basic requirement is that I want to dispatch requests sent to *.examples.com to cluster1 and then dispatch the remaining (other domains) requests to cluster2.

So I wrote something like this:

static_resources:

  listeners:
  - name: ingress0
    address:
      socket_address:
        address: 0.0.0.0
        port_value: 41000
    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
          stat_prefix: ingress_http
          http_protocol_options:
            accept_http_10: true
          route_config:
            name: local_route
            virtual_hosts:
            - name: local_service
              domains:
              - "*.examples.com"
              routes:
              - match:
                  connect_matcher:
                    {}
                route:
                  cluster: cluster1
                  upgrade_configs:
                  - upgrade_type: CONNECT
                    connect_config:
                      {}
              - match:
                  prefix: "/"
                route:
                  cluster: cluster1
            - name: direct # Fallback route
              domains:
                - "*"
              routes:
              - match:
                  connect_matcher:
                    {}
                route:
                  cluster: cluster2
                  upgrade_configs:
                  - upgrade_type: CONNECT
                    connect_config:
                      {}
              - match:
                  prefix: "/"
                route:
                  cluster: cluster2
          http_filters:
          - name: envoy.filters.http.router
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
              suppress_envoy_headers: true
          upgrade_configs:
          - upgrade_type: CONNECT

However it complains:

Only a single wildcard domain is permitted in route local_route

I have searched for info on this but no one asked how to set up a fallback virtual host. Does anyone have any suggestions for this?

yanavlasov commented 1 month ago

This error happens if you have multiple virtual hosts with the * domain. Please post full config that produces this error.

imlk0 commented 1 month ago

@yanavlasov Thanks for the clarification. I checked again and realized that I added two virtual hosts with "*" domain, which is an mistake. I will close this issue.