升級nginx支持TLSv1.2 TLSv1.3

這些天公司系統(tǒng)請了一些搞滲透測試的,檢測出網站“弱加密算法”,原因是之前的環(huán)境,nginx版本太低,只支持TLSv1.0 和TLSv1.1。所以現(xiàn)在想要配置TLSv1.2 TLSv1.3,則需要升級nginx,其中還包括了升級openssl,增加了http_v2_module 模塊來支持http2。這其中增加的http_v2_module 模塊可以在升級nginx的時候一起添加進去,因為我之前不知道,所以后面多了個單獨增加http_v2_module 模塊進行重新編譯。

一、升級nginx版本

直接參考這篇文章:https://blog.csdn.net/weixin_45414913/article/details/124801803

二、升級openssl

1.查看openssl版本

openssl version

2.下載最新穩(wěn)定版本的OpenSSL源碼包。

wget https://www.openssl.org/source/openssl-1.1.1i.tar.gz

這里要是下載不了的話可以手動下載完了再用ftp拖到服務器中

3.編譯源碼安裝

tar -xzvf openssl-1.1.1i.tar.gz
cd openssl-1.1.1i
./config
make && make install

然后另起一個服務器窗口,檢查一下openssl版本,不出意外的話會報:openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory錯誤,
執(zhí)行下面命令:

ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1
ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1

安裝成功

三、增加http_v2_module 模塊

1.查看nginx原有的模塊

/usr/local/nginx/sbin/nginx -V

image.png

后面的--with-http_v2_module就是配置好的時候出現(xiàn)的

2.我們的新配置信息就應該這樣寫,運行下面的命令即可,等配置完。

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module

有可能會報錯:SSL modules require the OpenSSL library.You can either do not enable the modules

我的情況是系統(tǒng)自帶了openssl 1.0.1,然后又自己裝了openssl 1.1.1,就出這個問題了。然后執(zhí)行:yum remove openssl-devel卸載就好了

3.編譯【特別注意】這里不要進行make install,否則就是覆蓋你之前的安裝

make

4.備份原有已安裝好的nginx

cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak

5.將剛剛編譯好的nginx覆蓋掉原有的nginx(這個時候【特別注意】這里nginx要停止狀態(tài))

/usr/local/nginx/sbin/nginx -s stop

cp ./objs/nginx /usr/local/nginx/sbin/

6.啟動nginx,仍可以通過命令查看是否已經加入成功

這時候啟動Nginx不要用 ./nginx -s reload,會報pid相關的錯誤,正確的啟動方式:/usr/local/nginx/sbin/nginx 即可。

四、配置TLSv1.2 TLSv1.3

參考鏈接:https://ssl-config.mozilla.org/#server=nginx&version=1.20.2&config=intermediate&openssl=1.1.1i&hsts=false&ocsp=false&guideline=5.6

image.png

驗證nginx是否支持TLS 1.3

我們可以通過 nginx -t 命令來驗證nginx是否支持TLS 1.3:

如果nginx支持TLS 1.3,將會輸出下面的信息 [root@iteblog.com ~]$ nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

如果nginx不支持TLS 1.3,將會輸出下面的信息 [root@iteblog.com /data/log]$ nginx -t

nginx: [warn] invalid value "TLSv1.3" in /etc/nginx/conf.d/default.conf:12

nginx: configuration file /etc/nginx/nginx.conf test failed

五、工具檢測

工具1:https://www.ssllabs.com/ssltest/analyze.html?d=h5-saic.matrixpr.net

image.png

工具2:https://geekflare.com/tools/tests/13p0ccp6a

image.png

參考:

https://blog.csdn.net/weixin_45414913/article/details/124801803
https://blog.csdn.net/inthat/article/details/122829324
https://blog.csdn.net/u010058695/article/details/122948842
https://blog.csdn.net/qq_36902628/article/details/118997046
https://blog.csdn.net/qubes/article/details/120546123
https://blog.csdn.net/qq_35624642/article/details/126442054
https://blog.csdn.net/weixin_44972135/article/details/106621593
https://www.265.me/read-25.html
https://blog.csdn.net/qq_34939308/article/details/120688177
http://www.yaotu.net/biancheng/785.html

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

相關閱讀更多精彩內容

友情鏈接更多精彩內容