好久没写啦
直至昨天才发现 Nginx 官方竟然也有一个Nginx-Quic项目
项目地址:https://hg.nginx.org/nginx-quic
官方使用手册:https://quic.nginx.org/README
博主的系统环境为:Fedora 32
这里就省略前置条件(安装什么cmake啊什么的 我觉得想折腾的人吧 总会自己研究的)
安装
依据条件 Nginx-Quic 需要依赖 Boringssl。
先进行Boringssl的编译
mkdir ~/Nginx-build
cd ~/Nginx-build
git clone https://github.com/google/boringssl # 建议非国内用户用这个拉取仓库
git clone https://gitee.com/mirrors/boringssl # 建议国内用户用这个拉取仓库会比较快
#以上两个二选一就行
cd boringssl
mkdir build
cd build
cmake ..
make -j4 #多线程进行以加快编译速度
到这里 如果你前置条件没有错误的话 以上步骤是完全不会报错的
Boringssl 构建文档:https://github.com/google/boringssl/blob/master/BUILDING.md
接下来则是 Nginx-Quic 的编译
cd ~/Nginx-build
hg clone -b quic https://hg.nginx.org/nginx-quic
# hg拉取nginx-quic的仓库
# 我个人没找到这个仓库的国内镜像站 所以国内的服务器可能会比较久
cd 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" 配置
注:以上编译步骤出自官方文档,这一步可能会出现以下的错误
./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.
可以尝试输入
cp ../boringssl/build/crypto/libcrypto.a /usr/local/lib
cp ../boringssl/build/ssl/libssl.a /usr/local/lib
再进行配置 看看是否还有以上报错 正常运行则
export CFLAGS="-Wno-error" #避免一些报错导致编译无法正常执行
make -j4 #多线程以加快速度
make install
当然 配置那一步 你可以根据你的需求自己添加模块 这跟原来的nginx是一摸一样的 没什么区别
以及 你也可以通过 ./auto/configure --help
可以查看configure的一些选项
--with-http_v3_module - 启用 QUIC 和 HTTP/3
--with-http_quic_module - 为较旧的 HTTP 版本启用 QUIC
--with-stream_quic_module - 启用 stream 模块的 QUIC 支持
以上是NGINX-QUIC版本新增的选项
本站构建配置如下:
./auto/configure --prefix=/usr/local/nginx \
--user=www \
--group=www \
--with-cc-opt=-I../boringssl/include \
--with-ld-opt='-L../boringssl/build/ssl -L../boringssl/build/crypto -ljemalloc -Wl,-rpath,/usr/local/luajit/lib' \
--with-http_stub_status_module \
--with-http_v3_module \
--with-http_v2_module \
--with-http_v2_hpack_enc \
--with-http_quic_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-http_realip_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-pcre=../../pcre-8.44 \
--with-pcre-jit \
--with-threads \
--with-file-aio \
--without-http_ssi_module \
--without-http_scgi_module \
--without-http_uwsgi_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-stream_quic_module \
--add-module=../../incubator-pagespeed-ngx-1.14.33.1-RC1 \
--add-module=../../headers-more-nginx-module \
--add-module=../../ngx_brotli \
--add-module=../../ngx_security_headers \
--add-module=../../lua-nginx-module-0.10.14 \
--add-module=../../ngx_devel_kit
总结
尝个鲜 感觉良好
顺带一提 安卓版的谷歌浏览器默认开启QUIC支持
至此目前本站为 Nginx-QUIC+PHP8.0+MYSQL的环境。