重新編譯 OpenSSL 1.1 & NGINX 1.25 用於 TLS 1.3(CentOS 7)

重新編譯 OpenSSL 1.1 & NGINX 1.25TLS 1.3 (CentOS 7), 按照你已經安裝在服務器上的場景 o 舊版本 openssl 與 nginx 服務關聯。

更具體地說,能夠激活 OpenSSL 1.1.1t 為了服務 NGINX,它與舊版本一起運行。 OpenSSL 1.0.2k.

# nginx -V
nginx version: nginx/1.25.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
# openssl version -a
OpenSSL 1.1.1t  7 Feb 2023

這意味著有兩個不同的版本 OpenSSL. 通過“yum“(1.0.2k-fips) 和一個版本 OpenSSL 手動編譯安裝 (openssl 1.1.1t).

傳統上,大多數人建議重新安裝 'OpenSSL' 在服務器級別。 這將需要執行命令: yum remove openssl. 但是這裡有一個大問題。 隨著舊版本的卸載 OpenSSL,您可能還需要卸載一些依賴的應用程序。 例如: nginx, MariaDB-server, cerbot另外還有更多。

一個更簡單的解決方案是重新編譯 openssl 1.1 & nginx 1.25TLS 1.3.

重新編譯教程 OpenSSL 1.1 & NGINX 1.25TLS 1.3 (CentOS 7)

在我的示例中,重新編譯是為了 nginx/1.25.0 & OpenSSL 1.1.1h 使用書店 OpenSSL 1.1.1t.

重新編譯 NGINX。

1. 創建文件: nginx-with-tls13-compile.sh

sudo nano nginx-with-tls13-compile.sh

添加腳本的位置:

#!/bin/bash

## nginx
NGINX=nginx-1.25.0.tar.gz

if [ ! -f "${NGINX}" ];then
    wget https://nginx.org/download/${NGINX}
fi

ND=$(basename $NGINX .tar.gz)
if [ ! -d "${ND}" ];then
    tar zxvf ${NGINX}
fi

cd ${ND}

## pre require package
## yum install gcc pcre-devel zlib-devel

./configure --prefix=/etc/nginx \
    --sbin-path=/usr/sbin/nginx \
    --modules-path=/usr/lib64/nginx/modules  \
    --conf-path=/etc/nginx/nginx.conf \
    --error-log-path=/var/log/nginx/error.log \
    --http-log-path=/var/log/nginx/access.log \
    --pid-path=/var/run/nginx.pid \
    --lock-path=/var/run/nginx.lock \
    --http-client-body-temp-path=/var/cache/nginx/client_temp \
    --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
    --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
    --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
    --http-scgi-temp-path=/var/cache/nginx/scgi_temp \
    --user=nginx \
    --group=nginx \
    --with-compat \
    --with-file-aio \
    --with-threads \
    --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_random_index_module \
    --with-http_realip_module \
    --with-http_secure_link_module \
    --with-http_slice_module \
    --with-http_ssl_module \
    --with-http_stub_status_module \
    --with-http_sub_module \
    --with-http_v2_module \
    --with-mail \
    --with-mail_ssl_module \
    --with-stream \
    --with-stream_realip_module \
    --with-stream_ssl_module \
    --with-stream_ssl_preread_module \
    --with-openssl=../$(basename $OPENSSL .tar.gz)
    
make

sudo make install

nginx -V

保存新文件。

2. 製作新的可執行文件:

chmod +x nginx-with-tls13-compile.sh

改寫 nginx.service

3.備份 nginx.service.

cat /lib/systemd/system/nginx.service > /srv/nginx_service.txt

(你可以選擇任何你想要的路徑 nginx_service.txt)

4.為服務創建文件 nginx: nginx.service

sudo nano nginx.service

5.在文件中新建文件 nginx.service 添加行:

##  /lib/systemd/system/nginx.service

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

6.將文件複製到'daemon“。

sudo cp nginx.service /lib/systemd/system/nginx.service

7. 複製文件後,使用以下命令更新文件權限:

sudo chmod 644 /lib/systemd/system/nginx.service

8.重新加載配置 systemd 使用以下命令將更改考慮在內:

sudo systemctl daemon-reload

9.重啟 ngnix.

sudo systemctl restart nginx

重新編譯 OpenSSL / NGINXTLS 1.3

10. 在文件所在的同一文件夾中 nginx-with-tls13-compile.shnginx.service,創建一個新文件: openssl-1.1-compile.sh.

sudo nano openssl-1.1-compile.sh

添加腳本:

#!/bin/bash

## Compile OpenSSL
OPENSSL=openssl-1.1.1h.tar.gz

DONE=openssl-compile-done

if [ ! -f "${DONE}" ] ;then
    wget https://www.openssl.org/source/${OPENSSL}

    tar zxvf ${OPENSSL}

    cd $(basename $OPENSSL .tar.gz)

    ./config shared no-idea no-md2 no-mdc2 no-rc5 no-rc4 --prefix=/usr/local/

    make

    sudo make install

    cd ..

    touch ${DONE}
fi

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib64/

read -n1 -r -p "$(/usr/local/bin/openssl version) - Press any key to continue..." key

source ./nginx-with-tls13-compile.sh

代替 ”OPENSSL=openssl-1.1.1h.tar.gz” 使用您要安裝的版本並使用 NGINX 重新編譯。

11. 使腳本可執行:

chmod +x openssl-1.1-compile.sh

12.運行命令:

./openssl-1.1-compile.sh

等待重新編譯過程完成 OpenSSL & NGINX.

重新編譯 OpenSSL 1.1 & NGINX 1.25 用於 TLS 1.3(CentOS 7)
OpenSSL &NGINX

如果我們可以幫助您或有補充,評論部分是開放的。

作為科技愛好者,我從2006年開始在StealthSettings.com上愉快地撰寫文章。我在操作系統方面有豐富的經驗,包括macOS、Windows和Linux,還熟悉編程語言和博客平台(WordPress),以及在線商店平台(WooCommerce、Magento、PrestaShop)。

如何 » Linux » 重新編譯 OpenSSL 1.1 & NGINX 1.25 用於 TLS 1.3(CentOS 7)
發表評論