Appearance
HTTP/2 加速与优化
HAProxy 2.4+ 原生支持 HTTP/2,可显著提升页面加载速度和并发处理能力。
HTTP/2 优势
| 特性 | HTTP/1.1 | HTTP/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/