nginx升級及遇到的問題error: SSL modules解決方法

0b973b0320c5ecc81444f1d15aa92375.jpeg

背景:由于發(fā)布出來的nginx的版本,被安全公司和白帽對nginx的掃描各種攻擊的手段,被發(fā)現(xiàn)的漏洞自然會在新的版本里進行解決掉。所以nginx也是需要不斷的進行升級來解決漏洞問題。

nginx升級一共可以分為5步:

1.下載最新版本nginx安裝包
2.解壓修改nginx源碼,隱藏版本和代理名稱
3.備份原nginx的nginx.conf文件和nginx啟動文件
4.配置和編譯新版本的nginx
5.替換nginx啟動文件

第1步:下載最新版本nginx安裝包

nginx下載官網(wǎng):下載地址:https://nginx.org/en/download.html

# 服務器下載nginx
wget http://nginx.org/download/nginx-1.22.0.tar.gz

下載穩(wěn)定的最新版本的nginx


image.png

第2步:解壓修改nginx源碼,隱藏版本和代理名稱(參考:http://www.itdecent.cn/p/e49389635d6d)

# 解壓
tar -zxvf nginx-1.22.0.tar.gz
cd nginx-1.22.0

第3步:備份原nginx的nginx.conf文件和nginx啟動文件(根據(jù)自己的安裝目錄備份)

#備份配置文件
cd /usr/local/nginx/conf
cp nginx.conf  nginx0731.conf
#備份啟動文件
cd /usr/local/nginx/sbin
cp nginx  nginx0731.bak

第4步:配置和編譯新版本的nginx

nginx安裝三大的命令的解釋

  • ./configure
    configure命令做了大量的“幕后”工作,包括檢測操作系統(tǒng)內(nèi)核和已經(jīng)安裝的軟件,參數(shù) 的解析,中間目錄的生成以及根據(jù)各種參數(shù)生成一些C源碼文件、Makefile文件等。
  • make
    make命令根據(jù)configure命令生成的Makefile文件編譯Nginx工程,并生成目標文件、最終 的二進制文件。
  • make install
    make install命令根據(jù)configure執(zhí)行時的參數(shù)將Nginx部署到指定的安裝目錄,包括相關目 錄的建立和二進制文件、配置文件的復制。
配置和編譯(正常順利情況下[下面無需再看,直接看第五步])
# 配置都是看你這邊是否需要配置https,我這邊是需要配置https訪問所以需要安裝 http_ssl_module模塊
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
# 編譯(此處是編譯,如果安裝的有了nginx,使用make編譯就行了,如果沒有安裝過的,可以執(zhí)行make install)
make
配置和編譯error(SSL modules require the OpenSSL library)
  • 配置錯誤( SSL modules require the OpenSSL library)如下圖


    8a18a09e31abf3af6e6a3d1fa68a70f.png
  • 解決辦法: 查詢openssl的安裝版本
#查看openssl的安裝版本及安裝目錄
openssl version -a
eg:
root@test5 nginx-1.22.0]# openssl version -a
OpenSSL 1.1.1l  24 Aug 2021
built on: Sun May  1 02:57:34 2022 UTC
platform: linux-x86_64
options:  bn(64,64) rc4(16x,int) des(int) idea(int) blowfish(ptr) 
compiler: gcc -fPIC -pthread -m64 -Wa,--noexecstack -Wall -O3 -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DKECCAK1600_ASM -DRC4_ASM -DMD5_ASM -DAESNI_ASM -DVPAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DX25519_ASM -DPOLY1305_ASM -DNDEBUG
OPENSSLDIR: "/usr/local/ssl/ssl"
ENGINESDIR: "/usr/local/ssl/lib/engines-1.1"
Seeding source: os-specific

# 修改配置信息
# 清除配置
[root@test5 nginx-1.22.0]# make clean
rm -rf Makefile objs
# 指定openssl安裝目錄--with-openssl=/usr/local/ssl/
[root@test5 nginx-1.22.0]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-openssl=/usr/local/ssl/
  • Make編譯時錯誤信息如[/usr/local/ssl//.openssl/include/openssl/ssl.h] Error 127
[root@test5 nginx-1.22.0]# make
make -f objs/Makefile
make[1]: Entering directory `/usr/local/nginx-1.22.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 `/usr/local/nginx-1.22.0'
make: *** [build] Error 2
  • Make編譯時錯誤解決辦法分為3步:

第1步:清除配置信息

# 清除配置信息
make clean
eg:
[root@test5 nginx-1.22.0]# make clean
rm -rf Makefile objs

第2步:修改nginx的源碼-修改加載openssl 路徑

#修改nginx目錄下auto/lib/openssl/conf的文件加載ssl的路徑
vi 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"
改為:
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"

第3步:重新配置和編譯nginx

[root@test5 nginx-1.22.0]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-openssl=/usr/local/ssl/
[root@test5 nginx-1.22.0]# make

第5步:替換nginx啟動文件

# 注意注意注意:先停掉原來的nginx服務,再執(zhí)行以下命令
cd /usr/local/nginx-1.22.0/objs
#復制新nginx啟動文件替換掉舊的啟動文件
cp nginx /usr/local/nginx/sbin/
cd /usr/local/nginx/sbin/
./nginx

如果能正常啟動則恭喜您,已經(jīng)完成了升級。

參考鏈接:

https://blog.51cto.com/ckl893/1682250

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容