系統:
linux 版本:centOS7
nginx版本:nginx-1.20.2
linux安裝nginx時 執行下面命令時報錯:
./configure --with-http_stub_status_module --with-http_ssl_module --prefix=/usr/local/nginx
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./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.
分析:原因是在 ./configure 時加了–with-http_ssl_module 這個需要依賴openssl 但是nginx沒有找到
--with-http_ssl_module 是 Nginx 編譯時的參數,用于啟用 SSL 支持。當啟用此模塊時,Nginx 將能夠處理 HTTPS 請求,并且可以配置為代理其他服務器的 HTTPS 流量。要在 Nginx 中啟用 SSL 支持,你需要在編譯 Nginx 時添加 --with-http_ssl_module 參數。這通常意味著你需要重新編譯 Nginx,因為 SSL 支持是作為 Nginx 的一個模塊來實現的。如果不需要支持https 不用加此參數
我檢查了一下linux是已經安裝了openssl的 這說明nginx里配置的openssl路徑和系統里的不是一個地方,我這里的openssl是系統安裝時就自帶的
[root@localhost nginx-1.20.2]# rpm -qa|grep openssl
openssl-libs-1.0.2k-19.el7.x86_64
xmlsec1-openssl-1.2.20-7.el7_4.x86_64
openssl-1.0.2k-19.el7.x86_64
[root@localhost nginx-1.20.2]# openssl version
OpenSSL 1.0.2k-fips 26 Jan 2017
解決辦法:
從官網下載openssl
https://openssl-library.org/source/
我下載的和我linux自帶版本一致的openssl-1.0.2k.tar.gz
解壓放在linux的/usr/local/src/package目錄下(目錄隨你定 但是后面要用到 保持一致即可)
然后重新執行(記得切換到你解壓后的nginx的bin目錄執行).
注意./configure和之前比加了--with-openssl=/usr/local/src/package/openssl-1.0.2k
#切換目錄
cd /usr/local/src/package/nginx-1.20.2
#和之前比加了--with-openssl=/usr/local/src/package/openssl-1.0.2k
#這個目錄對應的是你上面解壓的openssl的目錄
./configure --with-http_stub_status_module --with-openssl=/usr/local/src/package/openssl-1.0.2k --with-http_ssl_module --prefix=/usr/local/nginx
執行成功
后面再繼續你的安裝步驟即可
make
make install