原Nginx安装方式:源码编译安装 Nginx最新版下载地址:https://nginx.org/ 是否经过生产环境实操验证:是 -----------升级步骤开始---------- 1、备份老nginx的配置文件 cp /opt/nginx/conf/nginx.conf{,.bak} 2、解压新nginx tar -zxf nginx-1.20.2.tar.gz && cd nginx-1.20.2 3、备份新nginx的ssl配备文件并修改 cp auto/lib/openssl/conf{,.bak} vim auto/lib/openssl/conf 4、修改去掉.openssl路径 :39,42s/\/.openssl//g # CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include" # CORE_DEPS="$CORE_DEPS #$OPENSSL/.openssl/include/.openssl/ssl.h" # CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a" # CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a" # CORE_LIBS="$CORE_LIBS $NGX_LIBDL" 改为: CORE_INCS="$CORE_INCS $OPENSSL/include" CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h" CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libssl.a" CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libcrypto.a" CORE_LIBS="$CORE_LIBS $NGX_LIBDL" 5、 在新下载的nginx执行./configure的时候--prefix指定的目录是需要指向旧的nginx所指向的prefix目录,这些参数可以通过/opt/nginx/sbin/nginx -V查看到(每个人的nginx安装路径不同,要根据每个人的安装路径来查看) ./configure --prefix=/opt/nginx --user=nginx --group=nginx --with-http_gzip_static_module --with-http_stub_status_module --with-http_ssl_module 6、 执行make #执行完成之后不要执行make install指令,需要注意。 make 7、先备份旧的nginx二进制可执行程序 cp /opt/nginx/sbin/nginx{,.bak} 8、使用nginx-1.20.2的新二进制文件将nginx-1.16.1的二进制文件进行强制覆盖 [root@nginx-upgrade-test nginx-1.20.2]# cp -f objs/nginx /opt/nginx/sbin/nginx cp: overwrite ‘/opt/nginx/sbin/nginx’? y 9、返回新Nginx解压后的目录,敲入make upgrade进行平滑升级 [root@nginx-upgrade-test nginx-1.20.2]# make upgrade /opt/nginx/sbin/nginx -t nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok nginx: configuration file /opt/nginx/conf/nginx.conf test is successful kill -USR2 `cat /var/run/nginx.pid` sleep 1 test -f /var/run/nginx.pid.oldbin kill -QUIT `cat /var/run/nginx.pid.oldbin` 10、检查Nginx升级后的版本号 [root@nginx-upgrade-test sbin]# /opt/nginx/sbin/nginx -V nginx version: nginx/1.20.2 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/opt/nginx --user=nginx --group=nginx --with-http_gzip_static_module --with-http_stub_status_module --with-http_ssl_module -----------升级步骤结束----------