解决 Istio 报错 Ingress Gateway 404 Not Found SNI 路由不匹配修复
排查 客户端通过 HTTPS 访问 Istio Ingress Gateway 报 404 Not Found 或直接 TLS 连接重置,分析 Gateway CRD hosts 声明与 SNI 严格匹配。
问题现象
外部客户端调用 HTTPS 接口时,TLS 证书握手成功,但后续立刻返回 HTTP 404 Not Found:
$ curl -Iv https://api.mycorp.com/users
< HTTP/2 404
< server: istio-envoy
触发根因
- Istio
GatewayCRD 中配置的hosts列表未包含api.mycorp.com(例如仅写了*.internal.com); VirtualService中的gateways字段漏掉了当前 Ingress Gateway 的名称(默认仅绑定mesh内部服务间网格);- 客户端发送的 HTTP
Host头部与 TLS 握手层声明的 SNI 扩展字段不一致。
解决步骤
检查 Gateway 资源确保监听域名与证书绑定匹配
编辑 Gateway 配置:
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: public-gateway
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 443
name: https
protocol: HTTPS
tls:
mode: SIMPLE
credentialName: mycorp-tls-cert
hosts:
- "api.mycorp.com"
确保 VirtualService 明确绑定该公共网关
在 VirtualService 头部指定 gateways:
spec:
hosts:
- "api.mycorp.com"
gateways:
- public-gateway
http:
- route:
- destination:
host: users-service
验证确认
重新发送 HTTPS 请求:
网关精确匹配主机头并解密分发,成功返回 HTTP 200 及业务载荷。


