http代理

envoy.yaml

admin:
  access_log_path: /tmp/admin_access.log
  address:
    socket_address: { address: 127.0.0.1, port_value: 9901 }

static_resources:
  listeners:
  - name: listener_0
    address:
      socket_address: { address: 0.0.0.0, port_value: 10000 }
    filter_chains:
    - filters:
      - name: envoy.http_connection_manager
        config:
          stat_prefix: ingress_http
          codec_type: AUTO
          route_config:
            name: local_route
            virtual_hosts:
            - name: local_service
              domains: ["*"]
              routes:
              - match: { prefix: "/" }
                route: { cluster: some_service }
          http_filters:
          - name: envoy.router
  clusters:
  - name: some_service
    connect_timeout: 10s
    type: STATIC
    lb_policy: ROUND_ROBIN
    hosts: [{ socket_address: { address: 62.234.197.82, port_value: 80 }}]

本地配置hosts

127.0.0.1 xxxx.xxx.com

启动docker

$ docker run -d -p 10000:10000 -v `pwd`/envoy.yaml:/etc/envoy/envoy.yaml --name envoyproxy envoyproxy/envoy-alpine:v1.14.1

测试

curl --location --request GET 'http://xxx.xxxx.com:10000/im/account/get?accountId=liuk'

说明

当请求xxx.xxxx.com时,实际到本地的127.0.0.1:10000,即请求到envoy,envoy会将请求转发至62.234.197.82:80

tcp

envoy.yaml

static_resources:
    listeners:
    - address:
        socket_address:
            address: 0.0.0.0
            port_value: 10000
      filter_chains:
      - filters:
        - name: envoy.tcp_proxy
          config:
            stat_prefix: ingress_tcp
            cluster: baidu_server
            access_log:
              - name: envoy.file_access_log
                config:
                  path: /dev/stdout
    clusters:
    - name: baidu_server
      connect_timeout: 0.25s
      type: strict_dns
      lb_policy: round_robin
      hosts:
      - socket_address:
          address: 61.135.169.125
          port_value: 443

本地配置hosts

127.0.0.1 www.baidu.com

启动docker

$ docker run -d -p 10000:10000 -v `pwd`/envoy.yaml:/etc/envoy/envoy.yaml --name envoyproxy envoyproxy/envoy-alpine:v1.14.1

测试

curl https://www.baidu.com:10000