今天看了下cf的博客,居然cf都开始启用http3.0了,而且cf还贡献了对应的patch,那我们就按照教程也来进行启用。
https://blog.cloudflare.com/experiment-with-http-3-using-nginx-and-quiche/
首先是要下载nginx1.16.1和cf的quiche,这是官方文档里有的。 但是实际编译中还需要cmake > 3.0版本 go运行库 还有rust
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 wget http://nginx.org/download/nginx-1.16.1.tar.gz git clone --recursive https://github.com/cloudflare/quiche wget https://dl.google.com/go/go1.13.linux-amd64.tar.gz wget https://github.com/Kitware/CMake/releases/download/v3.15.4/cmake-3.15.4.tar.gz tar zxf cmake-3.15.4.tar.gz && cd cd cmake-3.15.4 && ./bootstrap && make && make install ln -s /usr/local/bin/cmake /usr/bin/cmaketar -C /usr/local -xzf go1.13.linux-amd64.tar.gz curl https://sh.rustup.rs -sSf | sh export PATH=$PATH :/usr/local/go/binexport PATH=$PATH :$HOME /.cargo/binexport GOROOT=/usr/local/goexport GOBIN=$GOROOT /binexport PATH=$PATH :$GOBIN
开始正式安装了
1 2 3 4 5 6 tar zxvf nginx-1.16.1.tar.gz cd nginx-1.16.1patch -p01 < ../quiche/extras/nginx/nginx-1.16.patch ./configure --prefix=/opt/server/nginx --with-pcre --with-stream --with-http_ssl_module --user=timo --with-http_mp4_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_stub_status_module --with-http_v2_module --with-http_v3_module --with-openssl=../quiche/deps/boringssl --with-quiche=../quiche make sudo make install
安装过程中可能会有如下的错误 比如这个
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 make -f objs/Makefile make[1]: 进入目录“/home/timo/nginx-1.16.1” mkdir -p ../quiche/deps/boringssl/build ../quiche/deps/boringssl/.openssl/lib ../quiche/deps/boringssl/.openssl/include/openssl \&& cd ../quiche/deps/boringssl/build \ && cmake -DCMAKE_C_FLAGS="" -DCMAKE_CXX_FLAGS="" .. \ && make VERBOSE=1 \ && cd .. \ && cp -r include/openssl/*.h .openssl/include/openssl \ && cp build/ssl/libssl.a build/crypto/libcrypto.a .openssl/lib CMake Error at CMakeLists.txt:1 (cmake_minimum_required): CMake 3.0 or higher is required. You are running version 2.8.12.2 -- Configuring incomplete, errors occurred! make[1]: *** [../quiche/deps/boringssl/.openssl/include/openssl/ssl.h] 错误 1 make[1]: 离开目录“/home/timo/nginx-1.16.1” make: *** [build] 错误 2
只要执行下面这个就行了
1 [timo@centos7 nginx-1.16.1]
比如下面这个
1 2 3 4 -- No package 'libunwind-generic' found libunwind not found. Disabling unwind tests. CMake Error at CMakeLists.txt:51 (message): Could not find Go
都提示你缺乏运行库了,可能没有装好go
再比如下面这个
1 2 3 4 5 6 7 make -f objs/Makefile make[1]: 进入目录“/home/timo/nginx-1.16.1” cd ../quiche && cargo build --release --no-default-features/bin/sh: cargo: 未找到命令 make[1]: *** [../quiche/target/release/libquiche.a] 错误 127 make[1]: 离开目录“/home/timo/nginx-1.16.1” make: *** [build] 错误 2
这个就是没有装好rust
最后就是修改nginx对应的配置了
1 2 3 4 5 6 7 8 9 10 listen 443 quic reuseport; listen 443 ssl http2; ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; add_header alt-svc 'h3-23=":443"; ma=86400' ;
然后就可以mac下用支持http3的curl进行请求了
1 2 brew install --HEAD -s https://raw.githubusercontent.com/cloudflare/homebrew-cloudflare/master/curl.rb ./curl -I https://blog.timoq.com/ --http3
用linux的可以参考https://github.com/curl/curl/blob/master/docs/HTTP3.md
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 git clone --recursive https://github.com/cloudflare/quiche cd quiche/deps/boringsslmkdir buildcd buildcmake -DCMAKE_POSITION_INDEPENDENT_CODE=on .. make cd ..mkdir -p .openssl/libcp build/crypto/libcrypto.a build/ssl/libssl.a .openssl/libln -s $PWD /include .opensslcd ../..QUICHE_BSSL_PATH=$PWD /deps/boringssl cargo build --release --features pkg-config-meta cd ..git clone https://github.com/curl/curl cd curl./buildconf ./configure LDFLAGS="-Wl,-rpath,$PWD /../quiche/target/release" --with-ssl=$PWD /../quiche/deps/boringssl/.openssl --with-quiche=$PWD /../quiche/target/release make
执行看看就是
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 HTTP/3 200 server: nginx/1.16.1 date : Wed, 23 Oct 2019 14:31:40 GMTcontent-type: text/html content-length: 78273 vary: Accept-Encoding etag: "5db0624a-131c1" strict-transport-security: max-age=15552000 x-frame-options: deny x-content-type-options: nosniff alt-svc: h3-23=":443" ; ma=86400 accept-ranges: bytes HTTP/3 200 date : Wed, 23 Oct 2019 14:32:58 GMTcontent-type: text/html; charset=utf-8 set-cookie: __cfduid=df2829c6d9106e2d9a762674e026f1c4d1571841178; expires=Thu, 22-Oct-20 14:32:58 GMT; path=/; domain=.blog.cloudflare.com; HttpOnly; Secure x-powered-by: Express cache-control: public, max-age=60 vary: Accept-Encoding cf-cache-status: HIT age: 7 expires: Wed, 23 Oct 2019 14:33:58 GMT alt-svc: h3-23=":443" ; ma=86400 expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" server: cloudflare cf-ray: 52a46c67da00d9a0-SIN