千家信息网

nginx 编译安装1.17.3版本,添加openssl参数报错问题解决

发表于:2025-02-04 作者:千家信息网编辑
千家信息网最后更新 2025年02月04日,背景最近在升级nginx1.14.1到nginx1.17.3版本时,发现了一个openssl的报错,记录一下问题的发生以及解决过程,供大家参考。问题升级nginx时,我按照惯例,使用原版本的编译参数,
千家信息网最后更新 2025年02月04日nginx 编译安装1.17.3版本,添加openssl参数报错问题解决

背景

最近在升级nginx1.14.1到nginx1.17.3版本时,发现了一个openssl的报错,记录一下问题的发生以及解决过程,供大家参考。


问题

升级nginx时,我按照惯例,使用原版本的编译参数,来进行1.17.3新版本的编译,如下:

# /usr/local/nginx/sbin/nginx -V取得编译参数:--prefix=/usr/local/nginx --with-http_ssl_module --with-openssl=/usr/local/openssl --with-http_stub_status_module --with-http_dav_module --with-http_realip_module --with-http_gzip_static_module --with-http_v2_module

利用旧版本的编译参数来编译新版本nginx,make的时候,发现出现了错误,操作与信息如下:

# tar -zxvf nginx-1.17.3.tar.gz# cd nginx-1.17.3# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-openssl=/usr/local/openssl --with-http_stub_status_module --with-http_dav_module --with-http_realip_module --with-http_gzip_static_module --with-http_v2_module# makemake -f objs/Makefilemake[1]: Entering directory `/root/soft/nginx-1.17.3'cd /usr/local/openssl \&& if [ -f Makefile ]; then make clean; fi \&& ./config --prefix=/usr/local/openssl/.openssl no-shared no-threads  \&& make \&& make install_sw LIBDIR=lib/bin/sh: line 2: ./config: No such file or directorymake[1]: *** [/usr/local/openssl/.openssl/include/openssl/ssl.h] Error 127make[1]: Leaving directory `

从报错信息上看,可以看到编译是openssl相关的组件报错了,可能是"--with-openssl=/usr/local/openssl" 这个参数导致。这里提到了"/usr/local/openssl/.openssl/include/openssl/ssl.h"这个文件,我尝试去找这个文件,发现文件找不到:(/usr/local/openssl是我自己安装的openssl)

# ll /usr/local/openssl/.openssl/ls: cannot access /usr/local/openssl/.openssl/: No such file or directory

可以发现.openssl这个目录本身是不存在的,应该是nginx 1.17.3版本编译的时候默认去找了"/usr/local/openssl/.openssl/"这个目录,所以导致了make失败。


解决

发现了问题可能的原因后,尝试修改一下nginx1.17.3添加openssl模块时候的相关编译信息(auto/lib/openssl/conf):

# vi 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"            //在该文件中,看到openssl的core相关目录,都被添加上了.openssl这级目录,尝试修改目录信息,去除.openssl这级目录:   # more auto/lib/open/ssl            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"

修改完auto/lib/openssl/conf的信息之后,重新编译安装nginx1.17.3,即可正常编译安装成功。

# make clean# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-openssl=/usr/local/openssl --with-http_stub_status_module --with-http_dav_module --with-http_realip_module --with-http_gzip_static_module --with-http_v2_module# make && make install


0