用于Rocky Linux 8.4的Nginx安装(通过源代码构建步骤)

简述

我想与Apache一起从源代码构建和安装最近流行的nginx。截至2021年10月,”1.21.3″是最新版本。

下载目标

可以在以下网址确认下载位置:http://nginx.org/download/

请留意以下事项。

请确保预先编译OpenSSL。由于需要源码,所以需要指定openssl的src目录。本次将在”/usr/local/src/”中放置”openssl-1.1.1l.tar.gz”并使用”–with-openssl”指定该目录。有关OpenSSL的安装,请参阅”在CentOS 7.2上安装OpenSSL(从源代码编译)”。

验证环境版本

ソフトウェアバージョンPCRE 8.45nginx1.21.3OSRockyLinux 8.4

PCRE 的安装

首先,安装PCRE。

在2021年1月的现在,应该引入PCRE而不是PCRE2。 最新版本是8.44。

wget  --trust-server-names https://downloads.sourceforge.net/project/pcre/pcre/8.45/pcre-8.45.tar.gz?ts=gAAAAABhcYSDrxoQfi9FRhQpv3QTSNRMT1wSsHXsSukcepH4gozvhyhC7ryXm8wE7NLOKBc5AWQZNxAYLPqsNNwgajFWvw2kJQ%3D%3D&r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Fpcre%2Ffiles%2Fpcre%2F8.45%2Fpcre-8.45.tar.gz%2Fdownload
tar xvzf pcre-8.45.tar.gz
cd pcre-8.45
./configure
make
make install

您只需要为这个一个选项提供本土语言的翻译:

安装nginx。

cd /usr/local/src
wget https://nginx.org/download/nginx-1.21.3.tar.gz
tar xvzf nginx-1.21.3.tar.gz
cd nginx-1.21.3
./configure --prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--with-pcre-jit \
--with-http_addition_module \
--with-http_dav_module \
--with-http_gzip_static_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_sub_module \
--with-mail \
--with-mail_ssl_module \
--with-openssl=/usr/local/src/openssl-1.1.1l
make
make install

#非推奨オプション
#--with-http_xslt_module \
#--with-ipv6 \
#--with-sha1=/usr/local \
#--with-md5=/usr/local \

如果存在/usr/sbin/nginx,则编译完成。

将启动脚本放置

让我们从CentOS的RPM中借用启动脚本。

/usr/lib/systemd/system/nginx.service
cat > /usr/lib/systemd/system/nginx.service << EOF
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/etc/nginx/logs/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/conf/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP \$MAINPID
ExecStop=/bin/kill -s QUIT \$MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

EOF

设定启动脚本

只需要一个选项,用中文将以下内容改写为本地语言:
剩下的就是通过这个脚本来确认启动和停止。

systemctl start nginx
systemctl stop nginx
systemctl enable nginx
广告
将在 10 秒后关闭
bannerAds