Nginx 1.25.0发布,开启HTTP 3时代的魔盒

2023-05-2619:53:56服务器及运维Comments1,677 views字数 1953阅读模式

Nginx 1.25.0发布,开启HTTP 3时代的魔盒文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html

日前Nginx发布了主线版本 1.25.0,该版本引入了对QUIC 和HTTP/3协议的支持,Nginx正式跨入HTTP/3时代。从1.25.0开始,QUIC和HTTP/3在Linux二进制包中启用。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html

QUIC和HTTP/3支持是实验性的,需要用户酌情使用。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html

从源头构建

HTTP/3支持具体支持由ngx_http_v3_module模块提供。对于源码编译版本需要用户自行启用该模块:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html

--with-http_v3_module文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html

编译参数启用。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html

HTTP/3的支持需要底层SSL库提供编译和运行时支持,Nginx官方建议通过BoringSSL,LibreSSL或者QuicTLS来提供支持。OpenSSL虽然也可以支持,但是不兼容早期的数据。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html

从源码构建需要使用configure命令(关详细信息,见Nginx官方文档):文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html

对于BoringSSL,使用文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html

./configure--with-debug--with-http_v3_module--with-cc-opt="-I../boringssl/include"--with-ld-opt="-L../boringssl/build/ssl-L../boringssl/build/crypto"

对QuicTLS配置:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html

/configure--with-debug--with-http_v3_module--with-cc-opt="-I../quictls/build/include"--with-ld-opt="-L../quictls/build/lib"

或者LibreSSL:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html

./configure--with-debug--with-http_v3_module--with-cc-opt="-I../libressl/build/include"--with-ld-opt="-L../libressl/build/lib"

配置后,使用make编译安装的。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html

配置

listen指令中的ngx_http_core_module模块有一个新参数快它在指定端口上启用HTTP/3 over QUIC。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html

quic参数也可以指定重用端口参数以使其与多个worker一起正常工作。有关指令列表,详见 ngx_http_v3_module说明。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html

启用地址验证:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html

quic_retry on;

启用0-RTT:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html

ssl_early_data on;

启用GSO (通用分段卸载):文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html

quic_gso on;

设定主机证书:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html

quic_host_key <filename>;

QUIC启用需要默认ssl_protocols指令指定为TLSv1.3协议。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html

默认情况下,GSO Linux特定优化被禁用。如果配置了相应的网络接口,请启用它支持GSO。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html

示例配置

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 {
listen 8443 quic reuseport;listen 8443 ssl;ssl_certificate certs/example.com.crt;ssl_certificate_key certs/example.com.key;location / {add_header Alt-Svc 'h3=":8443"; ma=86400';}}

故障排查

如果配置的HTTP/3没有生效,或者出现其他问题,可以通过一下排查方法进行排查。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html

1、检查nginx是使用正确版本SSL底层库构建的,并且在运行时使用了正确的SSL库,可以nginx -V显示当前使用SSL库的相关运行参数。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html

2、确保客户端实际通过QUIC发送请求。建议从一个简单的控制台客户端开始。例如ngtcp2在尝试之前确保服务器配置正确使用可能对证书非常挑剔的真实浏览器。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html

3、构建nginx时启用调试支持的并检查调试日志。它应该包含有关连接及其失败原因的所有详细信息。所有相关消息都包含“quic“ 字首,可以很容易筛选出来。为了进行更深入的排查,可以启用额外的调试 使用以下宏:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html

NGX_QUIC_DEBUG_PACKETS, NGX_QUIC_DEBUG_FRAMES, NGX_QUIC_DEBUG_ALLOC, NGX_QUIC_DEBUG_CRYPTO.
./configure--with-http_v3_module--with-debug--with-cc-opt="-DNGX_QUIC_DEBUG_PACKETS -DNGX_QUIC_DEBUG_CRYPTO"文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/42739.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/yunwei/42739.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定