By 李崇民 2023-08-26
支持HTTP3
1.1 HTTP3 简介
HTTP3 相关协议主要包括 QUIC 协议RFC 9000, RFC 9001, RFC 9002,RFC 9221 RFC 8899. 具体的HTTP/3(RFC 9114), 以及QPACK(RFC 9204). 这些协议在阿里巴巴的xquic项目的doc下有翻译成中文的协议,不过版本不是最新的。还可以参考深入剖析HTTP3协议。
QUIC(Quick UDP Internet Connection)是谷歌推出的一套基于UDP的传输协议,它实现了TCP + HTTPS + HTTP/2的功能,目的是保证可靠性的同时降低网络延迟。因为UDP是一个简单传输协议,基于UDP可以摆脱TCP传输确认、重传慢启动等因素,建立安全连接只需要一的个往返时间,它还实现了HTTP/2多路复用、头部压缩等功能。
1.2 HTTP3 配置示例
helper broker modules/njt_helper_broker_module.so
conf/mqtt.conf;
helper ctrl modules/njt_helper_ctrl_module.so
conf/ctrl.conf;
load_module modules/njt_http_split_clients_2_module.so;
load_module modules/njt_agent_dynlog_module.so;
load_module modules/njt_http_location_module.so;
load_module modules/njt_http_dyn_bwlist_module.so;
load_module modules/njt_dyn_ssl_module.so;
load_module modules/njt_http_vtsc_module.so;
cluster_name helper;
node_name node1;
worker_processes auto;
error_log logs/error.log info;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
server_name localhost;
# for better compatibility we recommend
# using the same port number for QUIC and TCP
listen 8443 quic reuseport; # QUIC
listen 8443 ssl; # TCP
ssl_protocols TLSv1.3;
location / {
# advertise that QUIC is available on the configured port
add_header Alt-Svc 'h3=":$server_port"; ma=86400';
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
1.3 测试HTTP3功能
在centos7下的http3测试工具可从Gitee https://gitee.com/njet-rd/http3-tools 下载
1.3.1 基于curl_http3 测试HTTP3
curl-http3 -vs -D/dev/stdout -o/dev/null --http3 https://quic.nginx.org
* processing: https://quic.nginx.org
* Trying 35.214.218.230:443...
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
* CApath: none
* Trying 35.214.218.230:443...
......
> Accept: */*
>
< HTTP/3 200
HTTP/3 200
......
1.3.2 基于hey进行压测
hey -n 10 -c 5 -h3 https://quic.nginx.org
Summary:
Total: 5.8759 secs
Slowest: 3.9820 secs
Fastest: 0.5170 secs
Average: 1.7755 secs
Requests/sec: 1.7019
Total data: 25190 bytes
Size/request: 2519 bytes
Response time histogram:
0.517 [1] |■■■■■■■■■■■■■
0.863 [1] |■■■■■■■■■■■■■
1.210 [1] |■■■■■■■■■■■■■
1.556 [2] |■■■■■■■■■■■■■■■■■■■■■■■■■■■
1.903 [3] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
2.250 [0] |
2.596 [0] |
2.943 [0] |
3.289 [1] |■■■■■■■■■■■■■
3.636 [0] |
3.982 [1] |■■■■■■■■■■■■
......
1.3.3 基于浏览器访问HTTP3
在浏览器输入 https://www.tmlake.com:8443/
1.4 http3配置指令
1.4.1 开启、关闭http3功能。
Syntax: "http3 on | off;
"
Default: http3 on;
Context: http, server
1.4.2开启、关闭对QUIC协议对HTTP/0.9功能的支持
Syntax: "http3_hq on | off;
"
Default: http3_hq off;
Context: http, server
1.4.3 设置在一个Connection内允许的请求stream数目最大值。
Syntax: "http3_max_concurrent_streams number;
"
Default: http3_max_concurrent_streams 128;
Context: http, server
1.4.4 设置在读写QUIC streams时的缓冲区大小
Syntax: "http3_stream_buffer_size size;
"
Default: http3_stream_buffer_size 64k;
Context: http, server
1.4.5 设置在Server端保存客户端Cid数目的最大值
Syntax: "quic_active_connection_id_limit number;
"
Default: quic_active_connection_id_limit 2;
Context: http, server
1.4.6 开启、关闭ebpf支持
本功能只在 Linux 5.7+ 以上内核版本中支持
Syntax: "quic_bpf on | off;
"
Default: quic_bpf off;
Context: main
1.4.7 开启关闭GSO功能
本功能只在支持UDP_SEGMENT功能的Linux(>= 4.18)版本中支持
Syntax: quic_gso on | off;
Default: quic_gso off;
Context: http, server
1.4.8 设置host_key文件
设置文件保存在加密状态重置(encrypt stateless reset)及地址验证令牌(address validation tokens)过程中要用到的密钥。缺省情况下,这个密钥会随机产生。
Syntax: "quic_host_key file;
"
Default: ——;
Context: http, server
1.4.9 开启关闭地址验证QUIC Address Validation 特性
Syntax: quic_retry on | off;
Default: quic_retry off;
Context: http, server