跳到主要内容位置

HTTP/3尝鲜

HTTP/3真牛逼

随着技术的发展,QUIC,HTTP3渐渐向我们走来。本文算是笔者的一个记录贴,因为实验的需要,需要实现基于QUIC的直播或者点播,因为对QUIC和HTTP3的不熟悉,所以开贴一点一点记录相关技术的实现。

部署#

本文通过部署Nginx官方的QUIC分支来实现的浏览器和nginx-quic服务器粗略的HTTP3通信 使用centos

下载BoringSSL#

BoringSSL 是由谷歌开发,从 OpenSSL 中分离的一个分支。BoringSSL 是 Chrome/Chromium、Android(但它不是 NDK 的一部分)和许多其他应用程序/程序中的 SSL 库。

由于nginx quic版本使用了新的tls1.3协议,需要openssl支持quic,但目前的openssl版本没有对应的支持,所以这里使用google的boringssl。

  mkdir nginx-http3  cd nginx-http3  git clone https://github.com/google/boringssl.git  cd boringssl  mkdir build  cd build  cmake ..  make

下载Nginx的QUIC版#

hg clone -b quic https://hg.nginx.org/nginx-quiccd nginx-quic./auto/configure --with-debug --with-http_v3_module \      --with-cc-opt="-I../boringssl/include" \      --with-ld-opt="-L../boringssl/build/ssl \      -L../boringssl/build/crypto"make make install

对编译好的nginx进行配置,启动#

进入/usr/local/nginx/conf/目录对nginx.conf进行配置、启动服务 服务器配置nginx.conf:#

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"';
        access_log logs/access.log quic;
        server {            # for better compatibility it's recommended            # to use the same port for quic and https            listen 8443 http3 reuseport;            listen 8443 ssl;
            ssl_certificate     server.crt;            ssl_certificate_key server.key;            ssl_protocols       TLSv1.3;
            location / {                # required for browsers to direct them into quic port                add_header Alt-Svc 'h3=":8443"; ma=86400';            }        }    }

测试效果#

打开最新的chrome或者edge浏览器 打开开发者工具 切换到network标签页访问页面会看到 protocol为h3说明开启成功。