You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将GKE集群中Nginx-Ingress配置为使用HTTP2替代HTTP1.1

在GKE的Nginx Ingress Controller(v1.23.2)中启用HTTP2替代HTTP1.1

一、客户端到Ingress Controller的HTTP2配置

HTTP2通常基于TLS(HTTPS)运行,请先确保你的Ingress已配置有效TLS证书。

1. 全局启用(所有Ingress生效)

编辑Nginx Ingress对应的ConfigMap,添加HTTP2启用配置:

kubectl edit configmap nginx-ingress-controller -n ingress-nginx

在ConfigMap的data块中新增:

use-http2: "true"

保存后,Nginx Ingress Controller会自动重载配置,所有Ingress将默认支持HTTP2。

2. 单个Ingress启用(仅针对特定域名)

在目标Ingress资源的注解中添加HTTP2配置:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: example-ingress
  annotations:
    nginx.ingress.kubernetes.io/http2: "true"
    # 可选:强制使用HTTP2推荐的TLS版本
    nginx.ingress.kubernetes.io/ssl-protocols: "TLSv1.2 TLSv1.3"
spec:
  tls:
  - hosts:
    - example.com
    secretName: example-tls-secret
  rules:
  - host: example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: example-service
            port:
              number: 80

二、Ingress Controller到后端服务的HTTP2配置

如果你的后端服务原生支持HTTP2,添加注解指定上游通信协议:

metadata:
  annotations:
    nginx.ingress.kubernetes.io/backend-protocol: "HTTP2"

该配置会让Nginx以HTTP2协议与后端服务建立连接。

验证配置生效

使用curl命令快速验证:

curl -I --http2 https://example.com

若响应头包含HTTP/2 200,则说明HTTP2已正常启用。也可通过浏览器开发者工具的「网络」面板,查看请求协议列是否显示h2。

内容的提问来源于stack exchange,提问作者Satyam Bhatia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 19:45:39