






















为了在CentOS 7.9上精确安装Nginx 1.28.1,最可靠的方法是编译安装。因为通过系统包管理器(yum)默认安装的通常是较旧的稳定版,无法指定具体的次要版本。
整个过程可以分为以下四个主要阶段,你需要以 root 权限或在命令前添加 sudo 来执行:
| 阶段 | 主要任务 | 关键指令/操作 |
|---|---|---|
下面是每个阶段的详细操作和说明:
第一步:安装编译环境
在编译开始前,需要安装必要的工具和开发库。
yum -y install gcc make pcre-devel zlib-devel openssl-devel
第二步:下载与编译Nginx 1.28.1
nginx-1.28.1.tar.gz 的链接,然后下载到服务器。这里以 /usr/local/src 目录为例:cd /usr/local/src
wget https://nginx.org/download/nginx-1.28.1.tar.gz
tar -zxvf nginx-1.28.1.tar.gz
cd nginx-1.28.1
./configure 脚本。下面的命令指定了安装路径并启用了一些常用模块(如SSL、HTTP/2)。你可以根据需求调整,使用 ./configure --help 查看所有选项。./configure --prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-stream \
--with-stream_ssl_module \
--with-http_gzip_static_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-threads \
--with-file-aio \
--with-pcre
http_ssl_module, http_v2_module: 用于HTTPS与HTTP/2。
stream, stream_ssl_module: 用于TCP/UDP代理(如未来可能的数据库负载均衡)。
http_gzip_static_module: 用于Vue3等静态文件预压缩。
http_secure_link_module, http_slice_module: 用于MinIO安全链接和文件分片。
threads, file-aio: 用于性能优化。
pcre: 用于正则表达式支持。
make
make install
第三步:安装后的配置与管理
echo 'export PATH=/usr/local/nginx/sbin:$PATH' >> ~/.bashrc
source ~/.bashrc
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
systemctl 管理,可以创建一个服务文件。vi /etc/systemd/system/nginx.service
将以下内容粘贴进去:[Unit]
Description=nginx - high performance web server
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
然后启用并启动服务:systemctl daemon-reload
systemctl enable nginx # 设置开机自启
systemctl start nginx # 启动Nginx
第四步:验证与基本管理
nginx -v 应显示版本 1.28.1。访问服务器IP,应能看到Nginx欢迎页。systemctl start nginxsystemctl stop nginxsystemctl restart nginxsystemctl reload nginxnginx -t/usr/local/nginx/conf/nginx.conf。网站配置文件通常放在同目录下或 /etc/nginx/conf.d/。/usr/local/nginx/html。/usr/local/nginx/logs/。注:如果已安装旧版Nginx,请先通过
yum remove nginx卸载,或确保编译安装路径与旧版不同,避免冲突。
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。