一、写在前面
1.1 报错提示
Nginx安装完成后,启用https代理,有报错信息;
报错提示如下
nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:101
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
1.2 错误原因
这个错误表明 Nginx 在配置文件中检测到了 ssl 相关的配置,但是 Nginx 没有被编译时启用 SSL 模块 (ngx_http_ssl_module)。
1.3 版本情况
系统:CentOS Linux release 7.9.2009 (Core)
Nginx:Nginx 1.26.0
依赖环境:
openssl-1.1.1t
(最开始时安装了openssl-3.3.1,但是一直报错,怀疑版本不匹配,更换了版本,但后面查找了一些资料,可能不是这个原因)
二、处理办法
2.1 查看openssl版本,是否安装;
openssl version
2.2 确认openssl库文件
ls /usr/local/openssl/lib
2.3 重新编译Nginx,启用SSL模块;
cd nginx-1.26.0 #定位到nginx解压目录下
./configure --prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-pcre \
--with-openssl=/usr/local/openssl
make
sudo make install
编译时报错(解决方法见下一节)
make -f objs/Makefile
make[1]: Entering directory `/root/nginx-install/nginx-1.26.0'
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 directory
make[1]: *** [/usr/local/openssl/.openssl/include/openssl/ssl.h] Error 127
make[1]: Leaving directory `/root/nginx-install/nginx-1.26.0'
make: *** [build] Error 2
2.4 测试配置文件有效性;
./nginx -t
或
/usr/local/nginx/sbin/nginx -t
2.5 重新加载配置文件
./nginx -s reload
或
/usr/local/nginx/sbin/nginx -s reload
三、Nginx编译报错处理方法
参考文档:编译安装nginx 1.26.0、openssl 3.0.13 常见报错 - 海yo - 博客园 (cnblogs.com)
报错
有点不同的是按照教程将nginx解压目录编辑$nginx_dir/auto/lib/openssl/conf目录改为如下内容
CORE_INCS="$CORE_INCS $OPENSSL/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/lib64/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/lib64/libcrypto.a"
CORE_LIBS="$CORE_LIBS $NGX_LIBDL"
CORE_LIBS="$CORE_LIBS $NGX_LIBPTHREAD"
if [ "$NGX_PLATFORM" = win32 ]; then
CORE_LIBS="$CORE_LIBS -lgdi32 -lcrypt32 -lws2_32"
fi
还有报错
cc: error: /usr/local/openssl/lib64/libssl.a: No such file or directory
cc: error: /usr/local/openssl/.openssl/lib/libcrypto.a: No such file or directory
处理办法
(1)将上面修改的$nginx_dir/auto/lib/openssl/conf内容再次修改;
CORE_LIBS="$CORE_LIBS $OPENSSL/lib64/libssl.a"
改为
CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libssl.a"
(2)编译时多加入1个条件:--with-openssl-opt="-L/usr/local/openssl/lib"
./configure --prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-pcre \
--with-openssl=/usr/local/openssl \
--with-openssl-opt="-L/usr/local/openssl/lib"
至此,编译成功,Nginx成功启用 SSL 模块,能够提供https代理。感谢2篇参考文档的作者。
离线安装Nginx参考文档: