1、官网下载最新版nginx,官网地址,https://nginx.org/en/download.html
2、上传下载的压缩包到linux服务器任意目录下
3、解压压缩包,tar -zxvf nginx-1.24.0.tar.gz
4、进入到解压文件夹内,cd nginx-1.24.0/
5、执行命令,./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-stream
具体都需要开启什么模块,由自己决定,这里我安装的时候遇到了个错误,详见下图
./configure: error: SSL modules require the OpenSSL library. You can either do not enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using --with-openssl=<path> option.
什么意思呢?原因是在尝试配置Nginx时,缺少系统依赖OpenSSL库,这是SSL模块所必需的,你可以以下2种方式解决:
不启用SSL模块:如果不需要SSL功能,可以在配置Nginx时不启用SSL模块。
在./configure
命令中不添加--with-http_ssl_module
参数,但是这样就不支持https协议了
安装OpenSSL库:
- 下载OpenSSL源代码,https://www.openssl.org/source/openssl-1.1.1k.tar.gz
- 解压,tar -xzvf openssl-1.1.1k.tar.gz
- cd openssl-1.1.1k
- 配置并构建OpenSSL,见一下代码
./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared
make
sudo make install
OK,安装完openssl依赖之后,继续第5步,把nginx的配置命令,改为
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-stream --with-openssl=/usr/local/ssl
6、make
这里又报了一个错误
make -f objs/Makefile make[1]: Entering directory `/opt/nginx-1.24.0' cd /usr/local/ssl \ && if [ -f Makefile ]; then make clean; fi \ && ./config --prefix=/usr/local/ssl/.openssl no-shared no-threads \ && make \ && make install_sw LIBDIR=lib /bin/sh: line 2: ./config: No such file or directory make[1]: *** [/usr/local/ssl/.openssl/include/openssl/ssl.h] Error 127 make[1]: Leaving directory `/opt/nginx-1.24.0' make: *** [build] Error 2
原因是在尝试编译安装nginx时。在执行make
命令时,无法找到config
脚本,导致编译过程失败
这是因为nginx预设openssl 路径参数,与我们上边手动安装的ssl目录不一致,路径不对需要调整
修改 nginx 1.24.0中 auto/lib/openssl/conf 的预设openssl 路径参数
进入到nginx解压目录,
vim auto/lib/openssl/conf
修改前配置
修改后配置
再次执行第5步、第6步。
至此、新版本的nginx编译完成,
7、进入nginx-1.24.0/objs/文件夹
把编译好的nginx可执行文件,替换旧的nginx文件,
8、重启nginx。
升级完成。