yum安装的nginx版本太老,有安全漏洞,所以进行升级,麒麟V10是centos7的版本,yun里没有最新的1.30版本,还是有漏洞,所以进行手动安装。

  1. 备份
# 1. 停止Nginx服务
systemctl stop nginx

# 2. 备份配置文件、网站数据、日志(备份到/root/nginx_backup)
mkdir -p /root/nginx_backup
cp -r /etc/nginx /root/nginx_backup/nginx_conf
cp -r /usr/share/nginx/html /root/nginx_backup/nginx_html
cp -r /var/log/nginx /root/nginx_backup/nginx_logs
  1. 卸载 yum 安装的旧版 Nginx 1.21.5
systemctl disable nginx
systemctl stop nginx
# 卸载主程序
yum remove -y nginx
# 清理残留依赖(可选,避免冲突)
yum autoremove -y

# 删除配置、执行文件、日志残留
rm -rf /etc/nginx
rm -rf /usr/sbin/nginx
rm -rf /var/log/nginx
rm -rf /var/lib/nginx
rm -rf /usr/share/nginx
  1. 安装新报,先下架nginx.1.30
wget http://nginx.org/download/nginx-1.30.0.tar.gz
tar -zxvf nginx-1.30.0.tar.gz
cd nginx-1.30.0
** 配置
./configure \
--prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-pcre
**安装
make && make install

–prefix=/usr/local/nginx:安装路径(推荐固定路径)
后面参数开启 HTTPS、压缩、状态监控等常用功能

  1. 系统支持自动启动
vi /usr/lib/systemd/system/nginx.service
******** 内如如下
[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=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target



****保存退出 重新加载
systemctl daemon-reload
启动和检查
# 启动Nginx
systemctl start nginx
# 设置开机自启
systemctl enable nginx
# 查看启动状态(显示active (running) 即为成功)
systemctl status nginx
最新版本
/usr/local/nginx/sbin/nginx -v
安装路径配置等信息
/usr/local/nginx/sbin/nginx -V

更多推荐