DEBUG.WIKI
PanstarCloud:部署应用,接入 AI,云服务器与 AI 网关
晚安云;香港 CN2 ¥15/月
V.PS:让项目靠近用户,亚太、欧洲、北美 KVM VPS

解决 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

触发根因

  1. Istio Gateway CRD 中配置的 hosts 列表未包含 api.mycorp.com(例如仅写了 *.internal.com);
  2. VirtualService 中的 gateways 字段漏掉了当前 Ingress Gateway 的名称(默认仅绑定 mesh 内部服务间网格);
  3. 客户端发送的 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 及业务载荷。