查看系统是否安装 openssl,如下 openssl已安装,但是没有安装 openssl-devel
[root@summergao nginx-1.27.3]# rpm -qa |grep openssl
openssl-1.0.2k-16.el7_6.1.x86_64
openssl-libs-1.0.2k-16.el7_6.1.x86_64
[root@summergao nginx-1.27.3]# yum list installed |grep openssl-devel
[root@summergao nginx-1.27.3]#
进入Nginx安装包
[root@summergao data]# cd nginx-1.27.3
[root@summergao nginx-1.27.3]# pwd
/data/nginx-1.27.3
[root@summergao nginx-1.27.3]# ls
auto CHANGES CHANGES.ru CODE_OF_CONDUCT.md conf configure contrib CONTRIBUTING.md html LICENSE Makefile man objs README.md SECURITY.md src
[root@summergao nginx-1.27.3]#
执行配置检测 ./configure 命令
./configure --prefix=/data/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-threads --with-stream --with-stream_ssl_preread_module --with-stream_ssl_module --without-http_rewrite_module
报错如下
checking for POSIX semaphores in libpthread ... found
checking for struct msghdr.msg_control ... found
checking for ioctl(FIONBIO) ... found
checking for ioctl(FIONREAD) ... found
checking for struct tm.tm_gmtoff ... found
checking for struct dirent.d_namlen ... not found
checking for struct dirent.d_type ... found
checking for sysconf(_SC_NPROCESSORS_ONLN) ... found
checking for sysconf(_SC_LEVEL1_DCACHE_LINESIZE) ... found
checking for openat(), fstatat() ... found
checking for getaddrinfo() ... found
checking for OpenSSL library ... not found
checking for OpenSSL library in /usr/local/ ... not found
checking for OpenSSL library in /usr/pkg/ ... not found
checking for OpenSSL library in /opt/local/ ... not found
checking for OpenSSL library in /opt/homebrew/ ... not found
./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.
解决办法
报错信息提示没找到OpenSSL库,一种解决方案:根据提示我们可以根据提示从源代码静态地构建OpenSSL库。
从OpenSSL官网下载OPENSSL,下载地址:https://www.openssl.org/source/
我这里需要下载老版本:openssl-1.0.2k.tar.gz
https://openssl-library.org/source/old/1.0.2/index.html
将资源文件下载上传至服务器 /data/ 下并解压。
[root@summergao data]# tar -zxvf openssl-1.0.2k.tar.gz
解压完成后,重新使用 –with-openssl= 参数指定检查配置时使用的openssl库,配置检测:
./configure --prefix=/data/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-threads --with-stream --with-stream_ssl_preread_module --with-stream_ssl_module --without-http_rewrite_module --with-openssl=/data/openssl-1.0.2k
然后编译安装即可(安装位置:/data/nginx)
[root@summergao nginx-1.27.3]# make && make install
进入nginx安装目录sbin目录下执行命令检查是否成功安装ssl模块
[root@summergao sbin]# cd /data/nginx/sbin/ && ./nginx -V
nginx version: nginx/1.27.3
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
built with OpenSSL 1.0.2k 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/data/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-threads --with-stream --with-stream_ssl_preread_module --with-stream_ssl_module --without-http_rewrite_module --with-openssl=/data/openssl-1.0.2k
[root@summergao sbin]#
至此Nginx安装完成