轉自:http://www.cnblogs.com/lzcys8868/p/9235538.htmlhtml
首先我以爲沒事就用綠盟掃漏洞的公司,就是閒的蛋疼,傻逼!很多服務器使用nginx,若是openssl 是靜態編譯的,直接將openssl 編譯到nginx裏面去了,這就意味着,單純升級openssl 是沒有任何效果的,nginx不會加載外部的openssl動態連接庫的,必須將nginx從新編譯才能夠根治。因此我說那些沒事就掃漏洞的公司是傻逼。。。linux
一.判斷nginx 是不是靜態編譯的nginx
[root@bogon ~]# /usr/local/nginx/sbin/nginx –Vgit
若是編譯參數中含有 –with-openssl= path ,或者有 –with-http_ssl_module ,則代表nginx 是靜態編譯的,那麼恭喜你在升級完openssl 以後還有從新編譯nginx,指定openssl 的目錄。github
查看當前openssl版本web
> openssl version -a OpenSSL 1.0.1e-fips 11 Feb 2013 built on: Wed Mar 22 21:43:28 UTC 2017 platform: linux-x86_64 options: bn(64,64) md2(int) rc4(16x,int) des(idx,cisc,16,int) idea(int) blowfish(idx) compiler: gcc -fPIC -DOPENSSL_PIC -DZLIB -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DKRB5_MIT -m64 -DL_ENDIAN -DTERMIO -Wall -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wa,--noexecstack -DPURIFY -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM OPENSSLDIR: "/etc/pki/tls" engines: rdrand dynamic
二. 升級openssl(後續須要從新編譯nginx,建議採用此方法升級openssl)服務器
> cd /opt/
> wget https://www.openssl.org/source/openssl-1.1.0j.tar.gz
> tar xvf openssl-1.1.0j.tar.gz
> cd /opt/openssl-1.1.0j/
> ./config --prefix=/usr/local/openssl
> echo $?
0
> make && make install
> echo $?
0 dom
將新編譯的openssl 替換老版本的ide
> mv /usr/bin/openssl /usr/bin/openssl.bak > mv /usr/include/openssl /usr/include/openssl.bak > ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl > ln -s /usr/local/openssl/include/openssl /usr/include/openssl
> cd /usr/local/openssl/lib/ > cp libssl.so.1.1 /usr/lib64/libssl.so.1.1 > cp libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
> ldconfig -v | grep ssl ldconfig: /etc/ld.so.conf.d/kernel-2.6.32-696.13.2.el6.x86_64.conf:6: duplicate hwcap 1 nosegneg ldconfig: /etc/ld.so.conf.d/kernel-2.6.32-696.16.1.el6.x86_64.conf:6: duplicate hwcap 1 nosegneg ldconfig: /etc/ld.so.conf.d/kernel-ml-aufs-3.10.5-3.el6.x86_64.conf:6: duplicate hwcap 1 nosegneg libssl.so.1.1 -> libssl.so.1.1 libssl.so.10 -> libssl.so.1.0.1e libssl3.so -> libssl3.so
> openssl version -a OpenSSL 1.1.0j 20 Nov 2018 built on: reproducible build, date unspecified platform: linux-x86_64 options: bn(64,64) rc4(16x,int) des(int) idea(int) blowfish(ptr) compiler: gcc -DDSO_DLFCN -DHAVE_DLFCN_H -DNDEBUG -DOPENSSL_THREADS -DOPENSSL_NO_STATIC_ENGINE -DOPENSSL_PIC -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DRC4_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DPADLOCK_ASM -DPOLY1305_ASM -DOPENSSLDIR="\"/usr/local/openssl/ssl\"" -DENGINESDIR="\"/usr/local/openssl/lib/engines-1.1\"" -Wa,--noexecstack OPENSSLDIR: "/usr/local/openssl/ssl" ENGINESDIR: "/usr/local/openssl/lib/engines-1.1"
三.從新編譯nginxui
查看nginx 中openssl 的版本
> ./nginx -V nginx version: nginx/1.12.2 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC) built with OpenSSL 1.0.1e-fips 11 Feb 2013 TLS SNI support enabled configure arguments: --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_perl_module --with-http_random_index_module --with-http_secure_link_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-threads --add-module=modules/nginx-rtmp-module
從新編譯nginx,並制定openssl 新版本的目錄。從新編譯nginx時,以前nginx 的配置參數要保證同樣
> cd /opt > git clone https://github.com/nginx/nginx.git > cd /opt/nginx
若是有添加的額外模塊,要將其模塊代碼也拉下來
下載 nginx-rtmp-module 模塊,並切換到穩定版本
> mkdir modules > cd modules > git clone https://github.com/arut/nginx-rtmp-module > cd nginx-rtmp-module > git checkout v1.2.0 > cd ..
> cp /opt/nginx/auto/configure ./ > ./configure --prefix=/usr/local/nginx --with-debug --with-pcre-jit --with-openssl=/usr/local/openssl --with-http_ssl_module --with-openssl=/usr/local/openssl --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_perl_module --with-http_random_index_module --with-http_secure_link_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-threads --add-module=modules/nginx-rtmp-module
make 報錯
[root@localhost nginx]# make make -f objs/Makefile make[1]: Entering directory `/opt/nginx' cd /usr/local/openssl \ && if [ -f Makefile ]; then make clean; fi \ && ./config --prefix=/usr/local/openssl/.openssl no-shared \ && 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 `/opt/nginx' make: *** [build] Error 2
解決方法以下:
修改nginx 源文件下的 /opt/nginx/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"
而後從新編譯安裝nginx
> ./configure --prefix=/usr/local/nginx --with-debug --with-pcre-jit --with-openssl=/usr/local/openssl --with-http_ssl_module --with-openssl=/usr/local/openssl --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_perl_module --with-http_random_index_module --with-http_secure_link_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-threads --add-module=modules/nginx-rtmp-module > make
注:此處千萬不要 執行make install,不然會覆蓋nginx 以前的配置文件
拷貝nginx的二進制目錄到nginx的安裝目錄下
> ps -ef|grep nginx root 4261 1 0 09:16 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf nobody 4267 4261 0 09:16 ? 00:00:00 nginx: worker process root 24701 5987 0 16:09 pts/3 00:00:00 grep nginx > kill -9 4261 > kill -9 4267 > cp /opt/nginx/objs/nginx /usr/local/nginx/sbin/
# 重啓nginx 查看nginx中的openssl 版本
> cd /usr/local/nginx/sbin > ./nginx -c /usr/local/nginx/conf/nginx.conf
>./nginx -V
nginx version: nginx/1.12.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC)
built with OpenSSL 1.1.0j 20 Nov 2018
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-debug --with-pcre-jit --with-openssl=/usr/local/openssl --with-http_ssl_module --with-openssl=/usr/local/openssl --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_perl_module --with-http_random_index_module --with-http_secure_link_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-threads --add-module=modules/nginx-rtmp-module
若是你將nginx的版本作了升級,直接替換可執行文件,啓動時會報錯:
> /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nginx: [alert] version 1.14.2 of nginx.pm is required, but 1.12.2 was found
緣由:perl文件,在make install的時候,也會安裝,若是不指定安裝目錄,這個文件會默認安裝到/usr/local/lib64/perl5/nginx.pm
而nginx.pm裏面記錄了nginx的版本號。因此,若是啓動nginx的時候,運行的nginx與nginx.pm版本號不一致就有問題,特別是升級nginx,或者一臺機器上部署了多個nginx
解決辦法:
1. --with-perl_modules_path=/home/webserver/nginx3/perl 把相關perl程序/模塊 安裝到指定目錄裏
2. 將舊版本的安裝目錄進行備份,而後切換到新版本的編譯目錄 , 執行 make install
再執行 ./nginx -c /usr/local/nginx/conf/nginx.conf 進行啓動
至此,openssl 升級結束。在此過程當中,遇到不少坑,以此文檔幫助須要沒事就升級openssl的小夥伴