kn007的个人博客
♥ You are here: Home > 软件与网络 > VPS > 小试HTTP3

小试HTTP3

by | 49 Comments


CF最近推出了个项目quiche,用于为Nginx添加QUIC支持,并支持HTTP3。

具体可以查看传送门。为此,我也更新了patch,重新整合了下。因为SPDY早已过期,所以这次新的patch就没再整合进来。

Patch为Nginx添加了以下特性:

Add QUIC Support.
Add HTTP2 HPACK Encoding Support.
Add Dynamic TLS Record support.

需要spdy的话,可以用这个Patch

目前已知Arch、Ubuntu 18可以直接编译成功。

像Debian 10和CentOS 8,需要编译部分组件,特别是需要最新版的rust支持。

通过以下命令可以安装最新版rust:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

然后在shell界面通过

source $HOME/.cargo/env

来临时添加环境变量调用。

具体patch使用,可以见上面CF文章传送门,我这里也大概讲下。

支持Nginx稳定版(1.16)和主要分支(1.17)的最新版本。

首先,获取quiche项目备用:

git clone --recursive https://github.com/cloudflare/quiche

其次,进入到Nginx源码目录,打我的patch或者是CF的patch。

接着,编译参数除了自定参数外,添加以下参数:

--with-http_v3_module
--with-openssl=/path/to/quiche/deps/boringssl
--with-quiche=/path/to/quiche

注意,按照实际更改位置。然后编译即可。也可以参考下我之前的文章:《我的Nginx编译之旅

Nginx配置方面,在Server段,需要两个listen,一个是udp,也就是quic,一个是tcp,也就是正常的443 SSL这些。

并且,需要新增一个Header,还有TLS1.3支持。配置大概如下:

server {
     # Enable QUIC and HTTP/3.
    listen 443 quic reuseport;

    # Enable HTTP/2 (optional).
    listen 443 ssl http2;

    ssl_certificate      cert.crt;
    ssl_certificate_key  cert.key;

    # Enable all TLS versions (TLSv1.3 is required for QUIC).
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;

    # Request buffering in not currently supported for HTTP/3.
    proxy_request_buffering off;
        
    # Add Alt-Svc header to negotiate HTTP/3.
    add_header alt-svc 'h3-27=":443"; ma=86400';
}

最早的时候,CF文章,忘记提示需要添加header,现在文章也已经有了。

其他就没啥坑了。

HTTP3测试可以通过quiche项目的工具检查,也可以通过这里检查。

不过讲道理,现在HTTP3没什么浏览器支持,QUIC也没多少支持的,虽说目前协议是已经是完善的了,但暂时仅限尝鲜。

但不得不吐槽的是Nginx官方速度真的慢,之前明明说好已经在给Nginx添加QUIC支持了,然后今年都快完了,还没弄出来。

另外quiche用了BoringSSL,而BoringSSL不支持OCSP Stapling,可以使用这个Patch解决。

自动更新OCSP Stapling File,请查看这篇文章《让Nginx使用BoringSSL时支持OCSP Stapling》。


然后目前博客服务器的Nginx已经rollback。。等以后再上了。

谈谈patch,下一版本,肯定是放弃spdy的了。

毕竟已经被废弃这么久了,加上明年上半年,主流浏览器也不会再支持TLS 1.0和TLS 1.1,那就更没有留的必要了。

我最迟可能也会在明年5月就取消这部分(SPDY、TLS 1.0和TLS 1.1)支持。

转载请注明转自:kn007的个人博客的《小试HTTP3

donate
有所帮助?

Comments

49 Comments立即评论
  1. 回复

    ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-g -O2 -fdebug-prefix-map=/data/builder/debuild/nginx-1.19.0/debian/debuild-base/nginx-1.19.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie' --add-module=../ngx_brotli --with-openssl=../openssl-1.1.1g --with-openssl-opt=enable-tls1_3 --with-http_v3_module --with-openssl=/root/build/quiche/deps/boringssl --with-quiche=/root/build/quiche

    执行make报错,下面是错误的代码

    root@cloud:~/build/nginx-1.17.9# make
    make -f objs/Makefile
    make[1]: Entering directory '/root/build/nginx-1.17.9'
    mkdir -p /root/build/quiche/deps/boringssl/build /root/build/quiche/deps/boringssl/.openssl/lib /root/build/quiche/deps/boringssl/.openssl/include/openssl \
    && cd /root/build/quiche/deps/boringssl/build \
    && cmake -DCMAKE_C_FLAGS="enable-tls1_3" -DCMAKE_CXX_FLAGS="enable-tls1_3" .. \
    && make VERBOSE=1 \
    && cd .. \
    && cp -r include/openssl/*.h .openssl/include/openssl \
    && cp build/ssl/libssl.a build/crypto/libcrypto.a .openssl/lib
    -- The C compiler identification is unknown
    -- Check for working C compiler: /usr/bin/cc
    -- Check for working C compiler: /usr/bin/cc -- broken
    CMake Error at /usr/share/cmake-3.7/Modules/CMakeTestCCompiler.cmake:51 (message):
    The C compiler "/usr/bin/cc" is not able to compile a simple test program.

    It fails with the following output:

    Change Dir: /root/build/quiche/deps/boringssl/build/CMakeFiles/CMakeTmp

    Run Build Command:"/usr/bin/make" "cmTC_7a50e/fast"

    make[2]: Entering directory
    '/root/build/quiche/deps/boringssl/build/CMakeFiles/CMakeTmp'

    /usr/bin/make -f CMakeFiles/cmTC_7a50e.dir/build.make
    CMakeFiles/cmTC_7a50e.dir/build

    make[3]: Entering directory
    '/root/build/quiche/deps/boringssl/build/CMakeFiles/CMakeTmp'

    Building C object CMakeFiles/cmTC_7a50e.dir/testCCompiler.c.o

    /usr/bin/cc enable-tls1_3 -o CMakeFiles/cmTC_7a50e.dir/testCCompiler.c.o -c
    /root/build/quiche/deps/boringssl/build/CMakeFiles/CMakeTmp/testCCompiler.c

    cc: error: enable-tls1_3: No such file or directory

    CMakeFiles/cmTC_7a50e.dir/build.make:65: recipe for target
    'CMakeFiles/cmTC_7a50e.dir/testCCompiler.c.o' failed

    make[3]: *** [CMakeFiles/cmTC_7a50e.dir/testCCompiler.c.o] Error 1

    make[3]: Leaving directory
    '/root/build/quiche/deps/boringssl/build/CMakeFiles/CMakeTmp'

    Makefile:126: recipe for target 'cmTC_7a50e/fast' failed

    make[2]: *** [cmTC_7a50e/fast] Error 2

    make[2]: Leaving directory
    '/root/build/quiche/deps/boringssl/build/CMakeFiles/CMakeTmp'

    CMake will not be able to correctly generate this project.
    Call Stack (most recent call first):
    CMakeLists.txt:14 (enable_language)

    -- Configuring incomplete, errors occurred!
    See also "/root/build/quiche/deps/boringssl/build/CMakeFiles/CMakeOutput.log".
    See also "/root/build/quiche/deps/boringssl/build/CMakeFiles/CMakeError.log".
    objs/Makefile:2062: recipe for target '/root/build/quiche/deps/boringssl/.openssl/include/openssl/ssl.h' failed
    make[1]: *** [/root/build/quiche/deps/boringssl/.openssl/include/openssl/ssl.h] Error 1
    make[1]: Leaving directory '/root/build/nginx-1.17.9'
    Makefile:8: recipe for target 'build' failed
    make: *** [build] Error 2
    root@cloud:~/build/nginx-1.17.9#

    1. MOD回复

      @thb: 你的环境问题。

  2. :razz: 博主我使用 nginx 1.18 + patch 构建完成后 http3check 显示 supported,而 1.19 同样操作后显示没启用,但是用 firefox 访问两者都能够使用 http/3,不知你有没有遇到

    1. MOD回复

      @稗田千秋: 正常的,你用另外一个就能测出来(好像我没分享)。

    2. MOD回复

      @稗田千秋: 你就当正常的就好了,现在nginx-dev也有nginx-quic分支了,有兴趣可以试试

  3. 回复

    使用patch命令。
    显示这个
    patch: **** Only garbage was found in the patch input.

    CloudFlare的patch没问题 但是kn007/patch上的就会这样 :razz: :cry:

    1. MOD回复

      @Cwrce2: 首先我的patch有对应的cf quiche版本,另外就是你确信下的是raw文件,而非html吧

    2. MOD回复

      @Cwrce2: 测试通过,感觉大几率是你下的是html而非raw文件。 :grin:

    3. 回复

      @kn007: 用nginx1.19结果就成功了。
      用1.18一直不行 :o

    4. MOD回复

      @Cwrce2: :grin: 那就不知道了,没用过stable版本,可能patch的位置有问题 :grin:

icon_wink.gificon_neutral.gificon_mad.gificon_twisted.gificon_smile.gificon_eek.gificon_sad.gificon_rolleyes.gificon_razz.gificon_redface.gificon_surprised.gificon_mrgreen.gificon_lol.gificon_idea.gificon_biggrin.gificon_evil.gificon_cry.gificon_cool.gificon_arrow.gificon_confused.gificon_question.gificon_exclaim.gif