对于那些在CentOS 7上想使用HTTP/3的nginx,但不想使用rpm或ninja的人,这是一份备忘录
原始事实和背景
我想在CentOS7上使用完全支持HTTP/1.1、HTTP/2和HTTP/3的nginx,并在搜索中发现了这篇文章。
Quiche的补丁似乎是用于实验性的HTTP/3版本,而使用OpenSSL的Google分支BoringSSL可能会更加方便,所以我选择了这个配置。
然而,我没有时间构建忍者,并且实际上我也不太理解npm是什么。我只知道它是用于安装包的工具?或者仅限于这种认识。
要求进行软件更新。
Cmake (一种跨平台的构建工具).
需要Cmake 3.10或更高版本才能使用BoringSSL。
在CentOS7的yum中只能安装2.8.12版本。因此,需要从源代码安装Cmake。
本文使用的是最新版本v3.25.1,但请根据需要自行替换为更新的版本。
$ wget https://github.com/Kitware/CMake/releases/download/v3.25.1/cmake-3.25.1-linux-x86_64.sh
$ sh cmake-3.25.1-linux-x86_64.sh
安装程序即将启动。
CMake Installer Version: 3.25.1, Copyright (c) Kitware
This is a self-extracting archive.
The archive will be extracted to: /root/cmake
If you want to stop extracting, please press <ctrl-C>.
CMake - Cross Platform Makefile Generator
Copyright 2000-2022 Kitware, Inc. and Contributors
All rights reserved.
(中略)
Do you accept the license? [yn]: y
会询问Cmake的安装目录。由于不太了解其中的区别,暂时选择了“否”,然后自己安装到了/usr/local/目录下。
By default the CMake will be installed in:
"/root/cmake/cmake-3.25.1-linux-x86_64"
Do you want to include the subdirectory cmake-3.25.1-linux-x86_64?
Saying no will install in: "/root/cmake" [Yn]: n
Using target directory: /root/cmake
Extracting, please wait...
Unpacking finished successfully
自己将其放入/usr/local/目录中。由于使用mv命令进行覆盖时可能会造成绝望的情况,因此应使用cp命令。
$ cp -r bin doc man share /usr/local/
Cmake已经更新到最新版本。
$ cmake --version
cmake version 3.25.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
使用Perl
我们需要在BoringSSL中使用Perl。由于yum可以轻松实现,因此我们将使用yum进行安装。
sudo yum install perl
去
需要Go来安装BoringSSL。(BoringSSL需要的软件很多吗?)可以使用yum进行安装。
sudo yum install golang
gcc 可以表示GNU编译器套件中的GNU编译器(GNU Compiler Collection)
CentOS7的标准4.8.5版本过旧,需要进行更新。
因此,通过yum安装devtoolset-11并设置PATH后,使用gcc进行操作。
由于 devtoolset-11 已包含在 centos-release-scl 存储库中,因此在安装 devtoolset-11 之前,需要先安装 centos-release-scl。
$ yum install centos-release-scl
$ yum install devtoolset-11
如果您要执行此操作,请在BoringSSL的cmake时运行以下命令。
export PATH=/opt/rh/devtoolset-11/root/bin:$PATH
卸载竞合库。
开放安全套接字层
如果已经安装了OpenSSL,为了避免与BoringSSL产生冲突(或者有可能冲突),需要卸载OpenSSL,故进行卸载操作。
通过 yum 进行卸载。
$ sudo yum remove uninstall
卸载已经安装好的东西。
$ cd /path/to/source/openssl
$ sudo make uninstall
安装必要的库
无聊的SSL
请按照BUILDING.md文件的说明进行安装。
但是如果按照这样进行安装,将会在意想不到的位置2上进行安装,所以请在configure中设置cmake的前缀。请各自进行设置。
$ git clone https://github.com/google/boringssl.git
# cd boringssl
$ mkdir build
$ cd build
$ cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lib/boringssl ..
$ make
$ make install
$ # リンカにlibssl.aやlibcrypto.aなどの静的ライブラリを読み込ませる必要があるので、コピーする
$ cp */*.a /usr/local/lib/boringssl/lib/
这是因为BoringSSL需要在cmake中使用C++11兼容的gcc。设置路径:
export PATH=/opt/rh/devtoolset-11/root/bin:$PATH
安装Nginx。
终于开始安装Nginx了。
由于在文章编写时,最新版本的Nginx 1.23.2还不支持QUIC,因此我们要从nginx-quic的仓库中进行下载。
$ wget -O nginx.tar.gz https://hg.nginx.org/nginx-quic/archive/quic.tar.gz
$ tar -zxvf nginx.tar.gz
$ cd nginx-quic-quic/
$ ./auto/configure --with-debug \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_v3_module \
--with-stream_quic_module \
--with-cc-opt="-I/usr/local/lib/boringssl/include" \
--with-ld-opt="-L/usr/local/lib/boringssl/lib" \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/run/nginx.pid \
--lock-path=/run/nginx.lock \
--user=nginx \
--group=nginx
$ make
$ make install
$ ./auto/configure –with-debug \
–with-http_ssl_module \
–with-http_v2_module \
–with-http_v3_module \
–with-stream_quic_module \
–with-threads \
–with-stream \
–with-stream_ssl_module \
–with-mail \
–with-mail_ssl_module \
–with-http_dav_module \
–with-http_flv_module \
–with-http_mp4_module \
–with-http_gunzip_module \
–with-http_gzip_static_module \
–with-http_realip_module \
–with-cc-opt=”-I/usr/local/lib/boringssl/include” \
–with-ld-opt=”-L/usr/local/lib/boringssl/lib” \
–prefix=/etc/nginx \
–sbin-path=/usr/sbin/nginx \
–conf-path=/etc/nginx/nginx.conf \
–error-log-path=/var/log/nginx/error.log \
–http-log-path=/var/log/nginx/access.log \
–pid-path=/run/nginx.pid \
–lock-path=/run/nginx.lock \
–user=nginx \
–group=nginx
将其添加到systemd中
只要把這樣的服務檔案放進去,它就可以運作。三。
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
故障排除
nginx:[emerg] 无法获取到用户名为”nginx”的信息。
由于用户不存在而导致的错误。
如果使用上述命令以“nginx”用户和“nginx”组创建,则可以使用下面的命令进行创建。
$ groupadd nginx
$ sudo useradd -g nginx -s /sbin/nologin -r nginx
顺便提一下(有点尴尬的事情)
listen 443 http3 reuseport;
如果不使用reuseport,将无法使用HTTP/3。
然而,似乎无法多次使用reuseport。
nginx: [emerg] duplicate listen options for 0.0.0.0:443 in /etc/nginx/conf.d/virtualhost.conf:5
nginx: configuration file /etc/nginx/nginx.conf test failed
换言之,Nginx上的HTTP/3不能托管多个域名。
快点普及HTTP/3吧,服务器软件不容易改变啊。5
好吧。我会停止已安装的Nginx并转回Apache。
http://mogile.web.fc2.com/nginx_wiki/nginx_wiki201510/start/topics/examples/systemd.html
如果有方法,请在评论中告诉我,我会跪求您的教导。
Apache不支持,Nginx是实验性的。LiteSpeed是支持的。