Java

nginx升级及遇到的问题error: SSL modules解

2022-07-31  本文已影响0人  挑战者666888
0b973b0320c5ecc81444f1d15aa92375.jpeg

背景:由于发布出来的nginx的版本,被安全公司和白帽对nginx的扫描各种攻击的手段,被发现的漏洞自然会在新的版本里进行解决掉。所以nginx也是需要不断的进行升级来解决漏洞问题。

nginx升级一共可以分为5步:

1.下载最新版本nginx安装包
2.解压修改nginx源码,隐藏版本和代理名称
3.备份原nginx的nginx.conf文件和nginx启动文件
4.配置和编译新版本的nginx
5.替换nginx启动文件

第1步:下载最新版本nginx安装包

nginx下载官网:下载地址:https://nginx.org/en/download.html

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

下载稳定的最新版本的nginx


image.png

第2步:解压修改nginx源码,隐藏版本和代理名称(参考:https://www.jianshu.com/p/e49389635d6d)

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

第3步:备份原nginx的nginx.conf文件和nginx启动文件(根据自己的安装目录备份)

#备份配置文件
cd /usr/local/nginx/conf
cp nginx.conf  nginx0731.conf
#备份启动文件
cd /usr/local/nginx/sbin
cp nginx  nginx0731.bak

第4步:配置和编译新版本的nginx

nginx安装三大的命令的解释

配置和编译(正常顺利情况下[下面无需再看,直接看第五步])
# 配置都是看你这边是否需要配置https,我这边是需要配置https访问所以需要安装 http_ssl_module模块
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
# 编译(此处是编译,如果安装的有了nginx,使用make编译就行了,如果没有安装过的,可以执行make install)
make
配置和编译error(SSL modules require the OpenSSL library)
#查看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/
[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

第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服务,再执行以下命令
cd /usr/local/nginx-1.22.0/objs
#复制新nginx启动文件替换掉旧的启动文件
cp nginx /usr/local/nginx/sbin/
cd /usr/local/nginx/sbin/
./nginx

如果能正常启动则恭喜您,已经完成了升级。

参考链接:

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

上一篇 下一篇

猜你喜欢

热点阅读