Nginx 版本快速升级切换

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx 版本快速升级切换相关的知识,希望对你有一定的参考价值。

前言:
本文章适合有Linux基础者阅读,需掌握源码方式安装nginx(文中作者直接省略了nginx的源码安装过程)

1.当前系统环境

系统 主机名 IP地址
Centos 7.4 xmh 10.0.0.200

2.nginx版本
当前版本:nginx-1.12.2
新版本:nginx-1.14.2
本文章使用源码包方式安装nginx

  • nginx存放:/application
  • nginx命名:以nginx版本命名

需求:需要将正在运行的nginx-1.12.2版本快速切换到nginx-1.14.2

3.版本切换思路

1.删除原有的软链接(rm -rf nginx)
2.为新版本目录创建新的软链接(nginx-1.14.2 --> nginx)
3.停止旧版本的服务进程(./nginx-1.12.2/sbin/nginx -s stop)
4.启动新版本的服务进程(./nginx/sbin/nginx)
注意:以上四个步骤需要通过 && 结合一起执行

4.nginx版本切换

#1.先将新版本的源码包编译到对应的目录
[[email protected] ~]# cd /application/
[[email protected] application]# ll
lrwxrwxrwx  1 root root  14 Jan 29 11:29 nginx -> ./nginx-1.12.2
drwxr-xr-x 11 root root 151 Jan 29 11:22 nginx-1.12.2
drwxr-xr-x  6 root root  54 Jan 29 11:30 nginx-1.14.2  #新版本nginx

#2.为不同版本nginx中的index.html文件追加内容(区分)
[[email protected] application]# echo "This is nginx 1.12.2 old" >nginx-1.12.2/html/index.html
[[email protected] application]# echo "This is nginx 1.14.2 new" >nginx-1.14.2/html/index.html

#3.将nginx原先的1.12.2版本切换到1.14.2(软链接方式)
[[email protected] application]# rm -rf ./nginx && ln -s ./nginx-1.14.2 ./nginx && ./nginx-1.12.2/sbin/nginx -s stop && ./nginx/sbin/nginx

[[email protected] application]# ll
lrwxrwxrwx  1 root root  14 Jan 29 11:35 nginx -> ./nginx-1.14.2 #版本切换成功
drwxr-xr-x 11 root root 151 Jan 29 11:22 nginx-1.12.2
drwxr-xr-x 11 root root 151 Jan 29 11:35 nginx-1.14.2

旧版本的nginx:
技术分享图片

新版本的nginx:
技术分享图片

以上是关于Nginx 版本快速升级切换的主要内容,如果未能解决你的问题,请参考以下文章

快速片段切换视图绑定 null

如何升级nodejs

Nginx 的平滑升级

Nginx 的平滑升级

CUDA升级和版本切换方法

如何使用sublime代码片段快速输入PHP头部版本声明