
1.准备工作
首先确保系统已更新并安装必要的开发工具:
sudo yum update -y
sudo yum groupinstall "Development Tools" -y
sudo yum install epel-release -y
sudo yum install pcre-devel zlib-devel openssl-devel wget -y
2.下载并编译安装 Nginx 1.21.4
# 下载 Nginx 1.21.4
wget http://nginx.org/download/nginx-1.21.4.tar.gz
tar -zxvf nginx-1.21.4.tar.gz
cd nginx-1.21.4
# 配置编译选项
./configure \
--prefix=/www/nginx \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_realip_module \
--with-threads \
--with-stream \
--with-stream_ssl_module
# 编译并安装 make && sudo make install
sudo vi /etc/systemd/system/nginx.service
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/www/nginx/logs/nginx.pid
ExecStartPre=/www/nginx/sbin/nginx -t
ExecStart=/www/nginx/sbin/nginx
ExecReload=/www/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
开放防火墙!就编译完成了!