模块 ngx_http_v2_module
这ngx_http_v2_module
module (1.9.5) 提供
支持 HTTP/2。
这个模块不是默认构建的,它应该使用
这--with-http_v2_module
configuration 参数。
已知问题
在 1.9.14 版本之前, 无法禁用客户端请求正文的缓冲 无论 proxy_request_buffering、fastcgi_request_buffering、uwsgi_request_buffering 和 scgi_request_buffering Directives值如何。
在 1.19.1 版本之前, lingering_close机制 不用于控制关闭 HTTP/2 连接。
示例配置
server { listen 443 ssl; http2 on; ssl_certificate server.crt; ssl_certificate_key server.key; }
请注意,通过 TLS 接受 HTTP/2 连接需要 “应用层协议协商”(ALPN) TLS 扩展 支持,自 OpenSSL 版本 1.0.2 起提供。
另请注意,如果 ssl_prefer_server_ciphers Directives
设置为值”on
”,
密码应配置为符合 RFC 9113 附录 A 黑名单并受客户端支持。
Directives
语法: |
http2 |
---|---|
默认值: |
http2 off; |
上下文: |
http ,server |
该Directives出现在版本 1.25.1 中。
使 HTTP/2 协议。
语法: |
http2_body_preread_size |
---|---|
默认值: |
http2_body_preread_size 64k; |
上下文: |
http ,server |
该Directives出现在版本 1.11.0 中。
设置size
每个请求的缓冲区
请求正文可以保存在其中
在开始处理之前。
语法: |
http2_chunk_size |
---|---|
默认值: |
http2_chunk_size 8k; |
上下文: |
http ,server ,location |
设置块的最大大小 响应正文被切成其中。 值过低会导致开销较高。 值太高会因 HOL 阻塞而影响优先级。
语法: |
http2_idle_timeout |
---|---|
默认值: |
http2_idle_timeout 3m; |
上下文: |
http ,server |
该Directives自 1.19.7 版本起已过时。 应改用 keepalive_timeout Directives。
设置不活动超时,超过此超时后,连接将关闭。
语法: |
http2_max_concurrent_pushes |
---|---|
默认值: |
http2_max_concurrent_pushes 10; |
上下文: |
http ,server |
该Directives出现在版本 1.13.9 中。
该Directives自 1.25.1 版本起已过时。
限制连接中并发推送请求的最大数量。
语法: |
http2_max_concurrent_streams |
---|---|
默认值: |
http2_max_concurrent_streams 128; |
上下文: |
http ,server |
设置并发 HTTP/2 流的最大数量 在连接中。
语法: |
http2_max_field_size |
---|---|
默认值: |
http2_max_field_size 4k; |
上下文: |
http ,server |
该Directives自 1.19.7 版本起已过时。 应改用 large_client_header_buffers Directives。
限制 HPACK 压缩的 request 标头字段。 该限制同样适用于 name 和 value。 请注意,如果应用了 Huffman 编码,则 解压后的 name 和 value 字符串的实际大小可能更大。 对于大多数请求,默认限制应该就足够了。
语法: |
http2_max_header_size |
---|---|
默认值: |
http2_max_header_size 16k; |
上下文: |
http ,server |
该Directives自 1.19.7 版本起已过时。 应改用 large_client_header_buffers Directives。
限制 HPACK 解压缩后整个请求标头列表的最大大小。 对于大多数请求,默认限制应该就足够了。
语法: |
http2_max_requests |
---|---|
默认值: |
http2_max_requests 1000; |
上下文: |
http ,server |
该Directives出现在版本 1.11.6 中。
该Directives自 1.19.7 版本起已过时。 应改用 keepalive_requests Directives。
设置可提供的最大请求数(包括推送请求) 通过一个 HTTP/2 连接, 之后,下一个客户端请求将导致连接关闭 以及建立新联系的需要。
必须定期关闭连接才能释放 每个连接的内存分配。 因此,使用的最大请求数过高 可能会导致内存使用过多,因此不建议这样做。
语法: |
http2_push |
---|---|
默认值: |
http2_push off; |
上下文: |
http ,server ,location |
该Directives出现在版本 1.13.9 中。
该Directives自 1.25.1 版本起已过时。
抢先发送
(推)
对指定uri
以及对原始请求的响应。
将仅处理具有绝对路径的相对 URI。
例如:
http2_push /static/css/main.css;
这uri
value 可以包含变量。
几个http2_push
Directives
可以在同一配置级别上指定。
这off
parameter 取消效果
的http2_push
Directives
继承自之前的配置级别。
语法: |
http2_push_preload |
---|---|
默认值: |
http2_push_preload off; |
上下文: |
http ,server ,location |
该Directives出现在版本 1.13.9 中。
该Directives自 1.25.1 版本起已过时。
支持预紧力的自动转换 链接到 “Link” 响应标头字段中指定的推送到推送请求中。
语法: |
http2_recv_buffer_size |
---|---|
默认值: |
http2_recv_buffer_size 256k; |
上下文: |
http |
设置每个工作程序 input 缓冲区的大小。
语法: |
http2_recv_timeout |
---|---|
默认值: |
http2_recv_timeout 30s; |
上下文: |
http ,server |
该Directives自 1.19.7 版本起已过时。 应改用 client_header_timeout Directives。
设置期望从客户端获得更多数据的超时, 之后,连接将关闭。
嵌入变量
这ngx_http_v2_module
模块
支持以下嵌入变量:
$http2
- 协商协议标识符:
“
h2
“ 表示基于 TLS 的 HTTP/2, “h2c
“ 对于通过明文 TCP 的 HTTP/2, 否则为空字符串。