解决 Envoy 报错 503 UC upstream TLS SNI hostname mismatch
分析 Envoy 代理上游报 503 UC upstream TLS SNI hostname mismatch 根因,详解 match_typed_subject_alt_names 与 SNI 对齐调优。
问题现象
通过 Envoy 转发 TLS 流量至上游后端时,请求被终止并返回 HTTP 503:
[2026-11-15T12:50:00.123Z] "GET /api HTTP/1.1" 503 UC 0 0 4 - "-" "curl/7.88.1" "req-1" "backend.internal" "-"
详细错误输出:upstream TLS SNI hostname mismatch: certificate subjectAltName does not match expected name。
触发根因
- Envoy 配置的
match_typed_subject_alt_names与后端证书 SAN 不一致:后端实际证书是针对api.example.com签发的,而 Envoy 配置期望校验backend.internal。
诊断排查步骤
- 提取后端服务的实际证书域名:
openssl s_client -connect 10.0.0.15:443 -showcerts </dev/null | openssl x509 -noout -text | grep DNS:
解决步骤与操作命令
步骤一:修正 Envoy UpstreamTlsContext 中的 SNI 与 SAN 匹配规则
在 envoy.yaml 中将 sni 与校验域名对齐:
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
sni: api.example.com
common_tls_context:
validation_context:
trusted_ca:
filename: /etc/envoy/ca.crt
match_typed_subject_alt_names:
- matcher:
exact: api.example.com
san_type: DNS
验证方法
重新发起测试: 握手顺利通过,请求返回 HTTP 200,Envoy 日志中无任何 SNI 警告。


