nginx 版本升级和添加模块详解

版本升级

把1.16.0版本升级为1.18.0
查看本机现在版本为1.16.0
[root@localhost ]# /usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.16.0

1,下载1.18.0的版本
[root@localhost ]# wget http://nginx.org/download/nginx-1.18.0.tar.gz
2,解压
[root@localhost ~]# tar xzf nginx-1.18.0.tar.gz
3,编译
[root@localhost ~]# cd nginx-1.18.0
查看编译的参数
[root@localhost ]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.16.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --group=nginx --user=nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream
编译
[root@localhost objs]# ./configure --prefix=/usr/local/nginx --group=nginx --user=nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream # --add-module=./echo-nginx-module-0.61 --add-module=./ngx_req_status-master

[root@localhost nginx-1.16.0]# make

查看编译的返回值是否正确
[root@localhost nginx-1.16.0]# $?
0
[root@localhost nginx-1.16.0]# make
按照原来的编译参数安装 nginx 的方法进行安装,只需要到 make,千万不要 make install 。如果make install 会将原来的配置文件覆盖

4,备份原 nginx 二进制文件

备份二进制文件和 nginx 的配置文件(期间nginx不会停止服务)
[root@localhost ~ ]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_$(date +%F)
5,复制新的nginx二进制文件,进入新的nginx源码包
[root@localhost ~]# cp /usr/local/nginx-1.18.0/objs/nginx /usr/local/nginx/sbin/2
6,测试新版本的nginx是否正常
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
7,给nginx发送平滑迁移信号(若不清楚pid路径,请查看nginx配置文件)

[root@localhost ~]# kill -USR2 `cat /var/run/nginx.pid`

8,从容关闭旧的Nginx进程

[root@localhost ~]# kill -WINCH `cat /var/run/nginx.pid.oldbin`

9、此时不重载配置启动旧的工作进程

[root@localhost ~]# kill -HUP `cat /var/run/nginx.pid.oldbin`

10、结束工作进程,完成此次升级

[root@localhost ~]# kill -QUIT `cat /var/run/nginx.pid.oldbin`

11、验证Nginx是否升级成功

[root@localhost ~]# /usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.18.0

升级完成

添加模块

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值