1、解压并编译新版的nginx
# 目前版本为1.18,解压一个1.21版本的nginx包
wget https://nginx.org/download/nginx-1.21.0.tar.gz
tar -zxf nginx-1.21.0.tar.gz
cd nginx-1.21.0/
[root@ubt-server nginx-1.21.0]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src# 安装编译
[root@ubt-server sbin]# pwd
/usr/local/nginx/sbin[root@ubt-server sbin]# ./nginx -V           # 先找到之前使用的是什么参数去安装的
...
...
configure arguments: --prefix=/usr/local/nginx# 找到参数后返回新版nginx的目录
[root@ubt-server nginx-1.21.0]# ./configure --prefix=/usr/local/nginx          # 使用和上面一样的参数去编译
[root@ubt-server nginx-1.21.0]# make
[root@ubt-server nginx-1.21.0]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src
2、备份老的二进制文件,将新的二进制文件替换上去
[root@ubt-server nginx-1.21.0]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old.running
[root@ubt-server nginx-1.21.0]# cp objs/nginx /usr/local/nginx/sbin/nginx# 发送USER2的型号,启用新的主进程来接收新的连接
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`# 让老版nginx处理完进程后优雅退出
kill -WINCH `cat /usr/local/nginx/logs/nginx.pid.oldbin`
3、确认服务是否成功替换
# 确认新版nginx已经成功接替,访问您的nginx服务是否可以正常运行或显示`
[root@ubt-server nginx-1.21.0]# ps aux | grep nginx
root       20942  0.0  0.0   4616   356 ?        Ss   23:44   0:00 nginx: master process /usr/local/nginx/sbin/nginx
root       23618  0.0  0.1   4624  2880 ?        S    23:57   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody     23619  0.0  0.1   5372  2856 ?        S    23:57   0:00 nginx: worker process
root       23622  0.0  0.1   6480  2324 pts/0    S+   23:57   0:00 grep --color=auto nginx# 若是您的服务正常运行,并可以正常显示就能将老进程关闭了
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
[root@ubt-server sbin]# ps aux | grep nginx
root       23618  0.0  0.1   4624  2880 ?        S    23:57   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody     23619  0.0  0.1   5372  2856 ?        S    23:57   0:00 nginx: worker process
root       23634  0.0  0.1   6480  2320 pts/0    S+   23:58   0:00 grep --color=auto nginx# 再次确认版本号,去web界面上确认一次您的服务是否可以正常显示
[root@ubt-server nginx-1.21.0]# cd /usr/local/nginx/sbin/
[root@ubt-server sbin]# ./nginx -v        # 可见nginx版本已被替换
nginx version: nginx/1.21.0