模块 ngx_http_v3_module
| 已知问题 配置示例 指令 http3 http3_hq http3_max_concurrent_streams http3_stream_buffer_size quic_active_connection_id_limit quic_bpf quic_gso quic_host_key quic_retry 内嵌变量 |
ngx_http_v3_module 模块 (1.25.0) 为 HTTP/3 提供实验性支持。
此模块默认不构建,应使用 --with-http_v3_module 配置参数启用。
建议使用提供 QUIC 支持的 SSL 库(如 BoringSSL、LibreSSL 或 QuicTLS)来构建和运行此模块。否则,当使用 OpenSSL 库时,将使用不支持早数据 (early data) 的 OpenSSL 兼容层。
已知问题
该模块是实验性的,用户需自行承担风险(caveat emptor)。
配置示例
http {
log_format quic '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" "$http3"';
access_log logs/access.log quic;
server {
# for better compatibility it's recommended
# to use the same port for http/3 and https
listen 8443 quic reuseport;
listen 8443 ssl;
ssl_certificate certs/example.com.crt;
ssl_certificate_key certs/example.com.key;
location / {
# used to advertise the availability of HTTP/3
add_header Alt-Svc 'h3=":8443"; ma=86400';
}
}
}
请注意,通过 TLS 接受 HTTP/3 连接需要 TLSv1.3 协议支持,该支持自 OpenSSL 1.1.1 版本开始提供。
指令
| 语法 |
http3 |
|---|---|
| 默认值 |
http3 on; |
| 上下文 |
http, server |
启用 HTTP/3 协议协商。
| 语法 |
http3_hq |
|---|---|
| 默认值 |
http3_hq off; |
| 上下文 |
http, server |
启用用于 QUIC 互操作性测试的 HTTP/0.9 协议协商。
| 语法 |
http3_max_concurrent_streams |
|---|---|
| 默认值 |
http3_max_concurrent_streams 128; |
| 上下文 |
http, server |
设置一个连接中 HTTP/3 请求流的最大并发数。
| 语法 |
http3_stream_buffer_size |
|---|---|
| 默认值 |
http3_stream_buffer_size 64k; |
| 上下文 |
http, server |
设置用于读取和写入 QUIC 流的缓冲区大小。
| 语法 |
quic_active_connection_id_limit |
|---|---|
| 默认值 |
quic_active_connection_id_limit 2; |
| 上下文 |
http, server |
设置 QUIC active_connection_id_limit 传输参数值。这是服务器上可存储的客户端连接 ID 的最大数量。
| 语法 |
quic_bpf |
|---|---|
| 默认值 |
quic_bpf off; |
| 上下文 |
main |
使用 eBPF 启用 QUIC 数据包路由。启用后,这允许支持 QUIC 连接迁移。
此指令仅在 Linux 5.7+ 上受支持。
| 语法 |
quic_gso |
|---|---|
| 默认值 |
quic_gso off; |
| 上下文 |
http, server |
启用使用分段卸载的优化批量发送模式。
优化发送仅在支持 UDP_SEGMENT 的 Linux 上受支持。
| 语法 |
quic_host_key |
|---|---|
| 默认值 | — |
| 上下文 |
http, server |
设置一个包含用于加密无状态重置和地址验证令牌的密钥的 file 文件。默认情况下,每次重新加载时会生成一个随机密钥。使用旧密钥生成的令牌将不被接受。
| 语法 |
quic_retry |
|---|---|
| 默认值 |
quic_retry off; |
| 上下文 |
http, server |
启用 QUIC 地址验证功能。这包括在 Retry 数据包或 NEW_TOKEN 帧中发送新令牌,并验证在 Initial 数据包中收到的令牌。
内嵌变量
ngx_http_v3_module 模块支持以下内嵌变量
$http3- 协商的协议标识符:HTTP/3 连接为“
h3”,hq 连接为“hq”,否则为空字符串。