1、查看现有的 nginx 编译参数
[root@nginx-server ~]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.17.5
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-google_perftools_module --with-http_geoip_module --with-pcre=../pcre-8.31 --with-stream
2.按照原来的编译参数安装 nginx 的方法进行安装,只需要到 make,千万不要 make install 。如果make install 会将原来的配置文件覆盖
[root@nginx-server ~]# cd /usr/local/nginx-1.22.1/
[root@nginx-server nginx-1.22.1]# ./configure --prefix=/usr/local/nginx --group=nginx --user=nginx ---with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-google_perftools_module --with-http_geoip_module --with-pcre=../pcre-8.31 --with-stream
[root@nginx-server nginx-1.22.1]# make
3.备份二进制文件和 nginx 的配置文件(期间nginx不会停止服务)
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_$(date +%F)
cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf_$(date +%F)
4.复制新的nginx二进制文件,进入新的nginx源码包
[root@nginx-server nginx-1.22.1]# cp objs/nginx /usr/local/nginx/sbin/
5、测试新版本的nginx是否正常
[root@nginx-server nginx-1.22.1]# /usr/local/nginx/sbin/nginx -t
6.停止和启动nginx,会影响业务运行,最后业务低峰期操作
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx