1. 首页

nginx支持http3.0

http3.0特性 [1]

  • 流多路复用
  • 流和连接级别的流量控制
  • 低延迟的连接建立,0-RTT
  • 连接迁移和 NAT 重新绑定的恢复能力
  • 认证加密的报头和数据

boringSSL编译安装

nginx-quic的加密模块使用的是boringSSL,所以先编译安装boringSSL。
先安装golang


apt-get install golang-go //JS中文网 – 前端进阶资源分享 https://www.javascriptc.com/ 趣聊CSS系列

在编译安装boringSSL


git clone https://boringssl.googlesource.com/boringssl cd boringssl/ mkdir build cd build cmake ../ make -j 8 //JS中文网 – 前端进阶资源分享 https://www.javascriptc.com/ 趣聊CSS系列

编译boringSSL过程中报错:


go: golang.org/x/crypto@v0.0.0-20200622213623-75b288015ac9: Get "https://proxy.golang.org/golang.org/x/crypto/@v/v0.0.0-20200622213623-75b288015ac9.mod": dial tcp 172.217.166.145:443: connect: connection refused //JS中文网 – 前端进阶资源分享 https://www.javascriptc.com/ 趣聊CSS系列

设置GOPROXY后继续编译成功


export GOPROXY=https://goproxy.io

Js中文网 – 前端进阶资源教程 www.javascriptC.com,typescript 中文文档
一个帮助开发者成长的社区,你想要的,在这里都能找到

编译完成后手动拷贝头文件和库文件固定的目录后,目录结构如下:


root@ubuntu:/usr/local/thirdparty/boringssl# find ./ -maxdepth 2 ./include/openssl ./lib/libssl.a ./lib/libcrypto.a

nginx-quic编译安装

nginx-quic目前还在开发过程中,有独立的开发分支,按照官方README [2] 的指引操作:


hg clone -b quic https://hg.nginx.org/nginx-quic ./auto/configure --with-debug \ --prefix=/usr/local/nginx-quic \ --with-http_v3_module \ --with-cc-opt="-I/usr/local/thirdparty/boringssl/include" \ --with-ld-opt="-L/usr/local/thirdparty/boringssl/lib" make -j 8 make install //JS中文网 – 前端进阶资源分享 https://www.javascriptc.com/ 趣聊CSS系列

如果遇到了


./auto/configure: error: certain modules require OpenSSL QUIC support. You can either do not enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using --with-openssl=<path> option. //JS中文网 – 前端进阶资源分享 https://www.javascriptc.com/ 趣聊CSS系列

请查看--with-cc-opt=-with-ld-opt=的路径是否正确。

安装完成后查看nginx详细信息


# ./sbin/nginx -V nginx version: nginx/1.19.2 built by gcc 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04) configure arguments: --with-debug --with-openssl=/home/wanghao/worker/opensourcecode/boringssl --prefix=/usr/local/nginx-quic //JS中文网 – 前端进阶资源分享 https://www.javascriptc.com/ 趣聊CSS系列

nginx配置文件


\#user nobody; worker_processes 2; error_log logs/debug.log debug; events { worker_connections 1024; } http { log_format quic '$remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent" "$quic" "$http3"'; access_log logs/access.log quic; server { listen 8443 http3 reuseport; listen 8443 ssl; server_name www.haha.com; client_max_body_size 4G; root /data; ssl_certificate ssl/server.crt; ssl_certificate_key ssl/server.key; ssl_protocols TLSv1.3; location / { autoindex on; autoindex_exact_size on; autoindex_localtime on; add_header Alt-Svc '$http3=":8443"; ma=86400'; } } } //JS中文网 – 前端进阶资源分享 https://www.javascriptc.com/ 趣聊CSS系列

启动后可以看到nginx监听的8443端口使用的udp协议


# netstat -annp |egrep nginx udp 0 0 0.0.0.0:8443 0.0.0.0:* 37737/nginx: master udp 0 0 0.0.0.0:8443 0.0.0.0:* 37737/nginx: master unix 3 [ ] STREAM CONNECTED 127155 37737/nginx: master unix 3 [ ] STREAM CONNECTED 127156 37737/nginx: master unix 3 [ ] STREAM CONNECTED 127157 37737/nginx: master unix 3 [ ] STREAM CONNECTED 127154 37737/nginx: master //JS中文网 – 前端进阶资源分享 https://www.javascriptc.com/ 趣聊CSS系列

nginx支持quic按照官方文档的指引很快就搞定了,但是支持quic的客户端却比较麻烦。

测试

TODO

参考

[1] docs.wxclimb.top/draft-ietf-…
[2] quic.nginx.org/readme.html

作者:feelc
链接:https://juejin.im/post/6876449316341284872

看完两件小事

如果你觉得这篇文章对你挺有启发,我想请你帮我两个小忙:

  1. 关注我们的 GitHub 博客,让我们成为长期关系
  2. 把这篇文章分享给你的朋友 / 交流群,让更多的人看到,一起进步,一起成长!
  3. 关注公众号 「画漫画的程序员」,公众号后台回复「资源」 免费领取我精心整理的前端进阶资源教程

JS中文网是中国领先的新一代开发者社区和专业的技术媒体,一个帮助开发者成长的社区,目前已经覆盖和服务了超过 300 万开发者,你每天都可以在这里找到技术世界的头条内容。欢迎热爱技术的你一起加入交流与学习,JS中文网的使命是帮助开发者用代码改变世界

本文著作权归作者所有,如若转载,请注明出处

转载请注明:文章转载自「 Js中文网 · 前端进阶资源教程 」https://www.javascriptc.com

标题:nginx支持http3.0

链接:https://www.javascriptc.com/4187.html

« 瞧,这就是Vue3新增特性
尝鲜Vue3之一:浏览器中如何断点调试Vue3 源码»
Flutter 中文教程资源

相关推荐

QR code