CentOS7服务器对Nginx离线升级

昨天用户发了一个紧急通知,要求尽快确认nginx使用的版本,发现 ≤ 1.21.5的nginx版本存在漏洞。
赶紧“nginx -v”一下… …
在这里插入图片描述
哎!!!提前和用户打好招呼,更新版本先停一会儿。
我们的项目部署在用户公司内网,服务器无法联网… …
在这里插入图片描述

1、确认安装的Nginx版本

  • 在任意目录下输入nginx -v,即可查看当前版本
[root@master /]# nginx -v
nginx version: nginx/1.12.2
[root@master /]# 
  • 如果无法直接使用nginx命令,可以进入到nginx文件的目录下执行,一般nginx在安装后,执行文件会在/usr/sbin/目录下
[root@master /]# cd /usr/sbin/
[root@master sbin]# ls nginx
nginx
[root@master sbin]# ./nginx -v
nginx version: nginx/1.12.2
[root@master sbin]# 
  • 还不行?使用find命令查询nginx执行文件的所在目录,看看哪个比较像。
[root@master /]# find -type f -name nginx
./etc/sysconfig/nginx
./etc/logrotate.d/nginx
./usr/sbin/nginx
[root@master /]# /usr/sbin/nginx -v
nginx version: nginx/1.12.2
[root@master /]# 

到这应该就可以确认nginx的安装版本了,如果还找不到nginx命令,那小弟也无能为力了,再去问问度娘吧。

2、上传新版本、解压

找了个能上外网的电脑,从Nginx官网下载了个新的nginx包,1.22.0,开启了我的更新之旅。
可将下载的安装包上传到任意目录,并进行解压

[root@master /]# cd home/
[root@master home]# rz
# 解压
[root@master home]# tar -zxvf nginx-1.22.0.tar.gz 

3、配置

[root@master home]# ls
nginx-1.22.0  nginx-1.22.0.tar.gz
[root@master home]# cd nginx-1.22.0
# 如果是https协议访问的话,需要在后面添加 --with-http_stub_status_module --with-http_ssl_module
[root@master nginx-1.22.0]# ./configure --prefix=/usr --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=/var/run/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx

咦~出问题了?

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre= option.

百度了一下发现服务器上缺少“pcre-devel”库文件

我们使用的centos版本是7.5.1804,访问下面地址直接搜索依赖包文件下载,访问地址:
https://vault.centos.org/7.5.1804/os/x86_64/Packages/
其他的centos版本可访问如下地址,选择对应的版本后进去下载:
https://vault.centos.org/

在这里插入图片描述

上传插件、安装、再次配置

[root@master home]# ls
nginx-1.22.0  nginx-1.22.0.tar.gz  pcre-devel-8.32-17.el7.x86_64.rpm
# 安装pcre-devel依赖
[root@master home]# rpm -ivh pcre-devel-8.32-17.el7.x86_64.rpm --nodeps --force
准备中...                          ################################# [100%]
正在升级/安装...
   1:pcre-devel-8.32-17.el7           ################################# [100%]

[root@master home]# cd nginx-1.22.0
# 再次配置nginx
[root@master nginx-1.22.0]# ./configure --prefix=/usr --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=/var/run/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx

在这里插入图片描述

参数描述
prefix配置安装目录
sbin-pathnginx执行文件的目录
conf-pathnginx配置文件的目录
error-log-pathnginx错误日志目录
http-log-pathnginx运行日志目录
pid-pathnginx运行时pid的目录
lock-path锁定文件目录,防止误操作,或其他使用
usernginx运行时的非特权用户
groupnginx运行时的非特权用户组

竟然成功了,下一步…

4、编译

注意:只执行make命令就行,不需要执行make install

[root@master nginx-1.22.0]# make

5、替换nginx执行文件

# 查找nginx文件位置
[root@master nginx-1.22.0]# find -type f -name nginx
./objs/nginx
# 备份原来的文件
[root@master nginx-1.22.0]# mv /usr/sbin/nginx /usr/sbin/nginx-old-1.12.2
# 将新文件拷贝到可执行目录下
[root@master nginx-1.22.0]# cp ./objs/nginx /usr/sbin/

6、启动nginx

[root@master nginx-1.22.0]# systemctl start nginx

7、重新查看nginx版本

[root@master nginx-1.22.0]# nginx -v
nginx version: nginx/1.22.0
[root@master nginx-1.22.0]# 

8、完活 收工~

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值