ตั้งค่า static HTTP proxy ด้วย Envoy: เชื่อม listener, route และ cluster
Envoy รับคำขอที่ listener, HTTP connection manager เลือก route แล้วส่งต่อไปยัง cluster ที่ระบุ คู่มือนี้ใช้ API v3 และแสดง HTTP listener หนึ่งตัวกับ static cluster ที่มี upstream สองตัว แหล่งข้อมูลที่อ่านเมื่อ 19-11-2026 มีหลายเวอร์ชัน ได้แก่ static configuration v1.37.7, การรันและ health check v1.38.9 และเอกสาร routing ปัจจุบัน ให้ตรวจด้วย binary ที่จะ deploy จริง ไม่ครอบคลุม xDS, TLS termination หรือ Kubernetes Gateway
Envoy รับคำขอที่ listener, HTTP connection manager เลือก route แล้วส่งต่อไปยัง cluster ที่ระบุ คู่มือนี้ใช้ API v3 และแสดง HTTP listener หนึ่งตัวกับ static cluster ที่มี upstream สองตัว แหล่งข้อมูลที่อ่านเมื่อ 19-11-2026 มีหลายเวอร์ชัน ได้แก่ static configuration v1.37.7, การรันและ health check v1.38.9 และเอกสาร routing ปัจจุบัน ให้ตรวจด้วย binary ที่จะ deploy จริง ไม่ครอบคลุม xDS, TLS termination หรือ Kubernetes Gateway
เส้นทางคำขอ
Listener รับฟังที่ address และ port ส่วน HTTP connection manager จัดการ HTTP และมี virtual host กับ route Envoy จับคู่ Host หรือ :authority กับ virtual host แล้วตรวจ route ตามลำดับ Route ระบุ cluster ซึ่งกำหนด upstream, timeout, load balancing และ health check ที่เลือกใช้ เมื่อ instance เปลี่ยนต้องปรับ address แบบ static
ตัวอย่าง
YAML นี้รับเฉพาะ loopback port 10000 ส่งทุก path ไป app_pool และตรวจ upstream ในเครื่องสองตัวที่ /healthz ปรับ address และวิธีตรวจให้ตรงบริการ HTTP check คาดหวัง 200 โดยปริยาย ช่วงเวลาและ threshold เป็นตัวอย่าง ไม่ใช่คำแนะนำทั่วไป endpoint ควรเบาและไม่มีผลข้างเคียง
static_resources:
listeners:
- name: local_http
address:
socket_address:
address: 127.0.0.1
port_value: 10000
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
route_config:
name: local_routes
virtual_hosts:
- name: app
domains: ["*"]
routes:
- match:
prefix: "/"
route:
cluster: app_pool
http_filters:
- name: envoy.filters.http.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
clusters:
- name: app_pool
type: STATIC
connect_timeout: 1s
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: app_pool
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 127.0.0.1
port_value: 8001
- endpoint:
address:
socket_address:
address: 127.0.0.1
port_value: 8002
health_checks:
- timeout: 1s
interval: 5s
unhealthy_threshold: 2
healthy_threshold: 2
http_health_check:
path: /healthzตรวจสอบ
ตรวจเวอร์ชัน บันทึกเป็น envoy.yaml แล้วรัน envoy --mode validate -c envoy.yaml config ที่ถูกต้องแสดง OK และรหัส 0; config ผิดแสดง error และรหัส 1 โหมด validate ไม่เริ่ม proxy หรือเชื่อมต่อเครือข่าย ตรวจ backend และ health path ทั้งคู่ เริ่ม Envoy ตามขั้นตอน deployment เรียก http://127.0.0.1:10000/ และดู log ใน test environment ที่ปลอดภัย ให้ check หนึ่งรายการล้มเหลวแล้วตรวจการฟื้นตัว ตัวอย่างนี้ไม่ได้รันหรือ validate ด้วย binary
แก้ปัญหาและกู้คืน
เมื่อ config ถูกปฏิเสธ ให้ตรวจ YAML, v3 type URL, field จำเป็น, ชื่อ cluster และ extension ใน build เมื่อพบ 404 ตรวจ Host/:authority, domains, ลำดับ route และ prefix เมื่อพบ 503 ตรวจ port, firewall, backend, log และ cluster stats ก่อนเปลี่ยน timeout เมื่อ host unhealthy ตรวจ path, status ที่คาดหวัง และ log คืน config ล่าสุดที่ใช้งานได้ validate และทดสอบคำขอจริง ตัวอย่างไม่มี admin interface; หากเปิดใช้ให้จำกัดในเครือข่ายจัดการที่ปลอดภัย
แหล่งข้อมูลและขอบเขต
[Static configuration, v1.37.7](https://www.envoyproxy.io/docs/envoy/v1.37.7/start/quick-start/configuration-static)
[Run Envoy, v1.38.9](https://www.envoyproxy.io/docs/envoy/v1.38.9/start/quick-start/run-envoy)
[Health checking, v1.38.9](https://www.envoyproxy.io/docs/envoy/v1.38.9/intro/arch_overview/upstream/health_checking)
[Route matching, current docs](https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_conn_man/route_matching.html)
[Installation, v1.38.9](https://www.envoyproxy.io/docs/envoy/v1.38.9/start/install)
address เป็นตัวอย่าง ไม่ครอบคลุมหรือดำเนินการ TLS, xDS, admin API, backend จริง, การรัน และ load test.