啟用 HTTP/3
啟用 TLSv1.3 協議支援
首先需要在 全域性配置
/通用
中確保已啟用 TLSv1.3 協議支援
配置 HTTP/3
在 全域性配置
/叢集分割槽
中,需要為分割槽新增 HTTP/3 監聽埠。由於 HTTP/3 使用 UDP 協議,這裡新增與 HTTPS 相同的 443 埠。
注意:請確認安全防火牆是否開放了 443 UDP 埠。
在 HTTP/3 埠配置完成之後,透過頁面規則新增 Alt-Svc
響應頭,可以告訴客戶端當前網站提供 HTTP/3 服務的埠。
Alt-Svc
響應頭格式如下:
Alt-Svc: <protocol-id>=<alt-authority>; ma=<max-age>
Example:
Alt-Svc: h3-25=":443"; ma=3600
Alt-Svc: h3=":443"; ma=3600, h3-25=":443"; ma=3600, h3-29=":443"; ma=3600
我們剛剛新增的 HTTP/3 埠為 443,因此這裡可以填寫 h3=":443"; ma=3600, h3-25=":443"; ma=3600, h3-29=":443"; ma=3600
。
驗證 HTTP/3
完成配置後,您可以透過以下幾種方式驗證 HTTP/3 是否正常工作:
使用 cURL 驗證
注意:需要使用支援 HTTP/3 的 cURL 版本。您可以參考官方文件:https://curl.se/docs/http3.html
- 直接使用 HTTP/3 協議:
curl -i --http3 https://your-domain.com/
HTTP/3 200
date: Fri, 28 Mar 2025 03:13:10 GMT
content-type: text/plain
req-id: 0000008000046ce4ce30000b
- 透過 Alt-Svc 自動協議升級:
curl -i --alt-svc altsvc.cache https://your-domain.com/
# 首次請求(HTTP/1.1)
HTTP/1.1 200 OK
Date: Fri, 28 Mar 2025 03:16:47 GMT
Content-Type: text/plain
alt-svc: h3=":443"; ma=3600, h3-25=":443"; ma=3600, h3-29=":443"; ma=3600
# 再次請求(自動升級至 HTTP/3)
HTTP/3 200
date: Fri, 28 Mar 2025 03:16:48 GMT
content-type: text/plain
使用 Docker 容器驗證
如果您沒有安裝支援 HTTP/3 的 cURL,可以使用預配置的 Docker 映象:
docker run -it --net=host --rm ymuski/curl-http3 curl -i --http3 https://your-domain.com/
瀏覽器驗證
主流瀏覽器(如 Chrome、Firefox、Edge)均已支援 HTTP/3。您可以透過瀏覽器的開發者工具檢視網路請求的協議版本。請確保瀏覽器已啟用 HTTP/3 功能支援。