Skip to content

HTTP/2 加速与优化

HAProxy 2.4+ 原生支持 HTTP/2,可显著提升页面加载速度和并发处理能力。

HTTP/2 优势

特性HTTP/1.1HTTP/2
多路复用需多连接单连接多流
Header 压缩HPACK
服务器推送不支持支持
流优先级不支持支持

基础配置

haproxy
frontend https_front
    bind *:443 ssl crt /etc/ssl/certs/ alpn h2,http/1.1
    default_backend web_backend

性能调优

haproxy
global
    # tune.h2.max-concurrent-streams 100
    # tune.h2.initial-window-size 524288

前端压缩优化

haproxy
frontend https_front
    bind *:443 ssl crt /etc/ssl/certs/ alpn h2
    compression algo gzip deflate br
    compression type text/html text/plain text/css application/json application/javascript

验证 HTTP/2

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