一、查看当前版本与备份
nginx -v
cp -r /usr/local/nginx /usr/local/nginx-old
获取configure 配置信息
二、下载新版本
Nginx 最新下载地址: https://nginx.org/en/download.html
选择当前最新稳定版本 :1.24.0
wget https://nginx.org/download/nginx-1.24.0.tar.gz
三、解压与编译安装
tar -zxvf nginx-1.24.0.tar.gz
cd nginx-1.24.0
###参照老的configure 配置信息
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-stream --with-stream_ssl_module --with-openssl=/opt/openssl-1.1.1k --conf-path=/usr/local/nginx/nginx.conf
make
不要make install
不要make install
不要make install
编译报错
/bin/sh: line 2: ./config: No such file or directory
make[1]: *** [/usr/local/openssl/.openssl/include/openssl/ssl.h] Error 127
make[1]: Leaving directory `/opt/nginx-1.24.0'
make: *** [build] Error 2
原因
出错是因为Nginx在编译时并不能在/usr/local/openssl/.openssl/ 这个目录找到对应的文件
其实我们打开/usr/local/openssl/这个目录,发现没有.opensslb目录
因此需要修改Nginx编译的文件,将此路径去掉就可以解决这个问题了
解决办法
vim /opt/nginx-1.24.0/auto/lib/openssl/conf
找到这么一段代码:
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"
保存后,
重新编译Nginx,再make即可
五、备份旧版本
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx-1.20.2
六、替换新版本
cd nginx-1.24.0
cp objs/nginx /usr/local/nginx/sbin/
七、make upgrade 升级
make upgrade
八、检查升级后的版本
nginx -v
参考链接: