• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

CentOS7服务器对Nginx离线升级

武飞扬头像
不要香菜多放葱
帮助1

昨天用户发了一个紧急通知,要求尽快确认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-path nginx执行文件的目录
conf-path nginx配置文件的目录
error-log-path nginx错误日志目录
http-log-path nginx运行日志目录
pid-path nginx运行时pid的目录
lock-path 锁定文件目录,防止误操作,或其他使用
user nginx运行时的非特权用户
group nginx运行时的非特权用户组

竟然成功了,下一步…

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、完活 收工~

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhfiigic
系列文章
更多 icon
同类精品
更多 icon
继续加载