一、准备
1. 新建一个目录存放安装包。可以放在/root/nginx 。
2. 升级前对原nginx的配置文件 ‘ nginx.conf ’ 做下备份。
3. 先查看下当前nginx安装位置和版本号。
ps -ef | grep nginx
root 115149 1 0 14:18 ? 00:00:00 nginx: master process /usr/local/nginx-1.13.4/sbin/nginx
nobody 115150 115149 0 14:18 ? 00:00:00 nginx: worker process
root 115208 110517 0 14:50 pts/0 00:00:00 grep nginx
/usr/local/nginx-1.13.4/sbin/nginx -V
nginx version: nginx/1.13.4
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx-1.13.4 --with-http_stub_status_module --with-http_ssl_module
二、开始升级 gogogo ~
1. 解压下载的新版本nginx文件
cd /root/nginx
tar -zxvf nginx-1.16.1.tar.gz
cd nginx-1.16.1
./configure --prefix=/usr/local/nginx-1.13.4 --with-http_stub_status_module --with-http_ssl_module&&make 【nginx-1.13.4这个文件夹是我之前版本的文件夹名称,按照自己的实际情况写哦,直接粘贴可能会有问题】
2. 开始替换新老版本的执行文件
cd /usr/local/nginx-1.13.4/sbin
mv nginx nginx.old
cp -r /root/nginx/nginx-1.13.4/objs/nginx .
3. 查看下nginx配置文件是否正确
/usr/local/nginx-1.13.4/sbin/nginx -t
执行后的提示信息:
nginx: the configuration file /usr/local/nginx-1.13.4/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.13.4/conf/nginx.conf test is successful
[root@wcce sbin]# kill -USR2 `cat /usr/local/nginx-1.13.4/logs/nginx.pid`
nginx-1.13.4/
4. 开始升级nginx版本
kill -USR2 `cat /usr/local/nginx-1.13.4/logs/nginx.pid`
5. 将旧版本nginx的pid改为nginx.pid.oldbin
cd /usr/local/nginx-1.13.4/logs
ls -lit nginx.pid.oldbin
6. 退出旧版本nginx
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
7. 最后查看下nginx的版本号
/usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.16.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx-1.13.4 --with-http_stub_status_module --with-http_ssl_module
成功升级!