如何在 NGINX 上啟用 TLSv1.3?VestaCP / CentOS 或 Ubuntu

在本教程中,您將學習如何 激活 TLSNGINX 上的 v1.3. 這是什麼意思 TLSv 1.3, 它有什麼幫助 為什麼 你需要 在網絡服務器上 TLS 可以激活. 對於帶有管理系統的服務器 VestaCP (CentOS 或 Ubuntu)有點困難 激活 TLS 1.3 比在 cPanel 服務器上更好,但這並非不可能。

為什麼更好 TLS 1.3比 TLS 1.2?

TLS (Transport Layer Security)密碼協議 這確保 連接安全 在計算機和它所屬的網絡之間。 TLS 它用於以下應用: 電子郵件, 通訊, 語音和視頻通話 (VoIP), 但特別是在 HTTPS. 確保用戶的計算機或智能手機與訪問頁面的 Web 服務器之間的安全通信。

TLS 1.3 提供一個 更高的速度 連接客戶端-服務器和一個 而且安全 通過消除一些算法。 之間的差異 TLSv1.2 和 TLSv1.3.

關於 HTTPS, SSL (Secure Sockets Layer)我在其他文章中也說過:

如何在 NGINX 上啟用 TLS 1.3?具有 VestaCP 管理的伺服器 / CentOS

在你看到你如何激活之前 TLSv1.3 on NGINX,你需要考慮一些最低要求 TLS 1.3.

  1. NGINX 1.13.x 或更高版本
  2. 證書 TLS 有效
  3. 具有正確配置的 DNS 的活動域名 – 可在 Internet 上訪問
  4. 證書 TLS / SSL 有效的。 也可以 Let’s Encrypt.

Pe VestaCP 很久以前安裝的,我們只有可用的協議 TLS 1.2. 我在許多教程中看到它就足夠了 nginx.conf 讓我們為 ca 添加以下行 TLS 1.3 待激活:

server {

  listen 443 ssl http2;
  listen [::]:443 ssl http2;

  server_name example.com;
  root /var/www/example.com/public;

  ssl_certificate /path/to/your/certificate.crt;
  ssl_certificate_key /path/to/your/private.key;

  ssl_protocols TLSv1.2 TLSv1.3;

偽造的。 如果 服務器 CentOS 與管理 VestaCP, NGINX 尚未編譯 最低版本 OpenSSL 1.1.1.1, ssl_protocols TLSv1.2 TLSv1.3; 進入 nginx.conf .. 它根本沒有幫助。

[root@north ~]# nginx -V
nginx version: nginx/1.22.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

所以在上面的例子中 Nginx 1.22.0 是兼容版本 TLS 1.3,但是圖書館幫不了我們 OpenSSL 1.0.2k-fips.

激活 TLSv1.3 on Nginx,需要先安裝子庫和開發包。 Development Tools. 它運行在 CentOS 7個命令行:

yum install gcc gcc-c++ pcre-devel zlib-devel make unzip gd-devel perl-ExtUtils-Embed libxslt-devel openssl-devel perl-Test-Simple
yum groupinstall 'Development Tools'

1.安裝最新版本 OpenSSL

此時最新版本為 OpenSSL 1.1.1p,但據我所知,已經有並且 OpenSSL 3. 你可以找到來源 OpenSSL。ORG.

cd /usr/src
wget https://www.openssl.org/source/openssl-1.1.1p.tar.gz
tar xvf openssl-1.1.1p.tar.gz 
mv openssl-1.1.1p openssl
cd openssl
./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl --libdir=/lib64 shared zlib-dynamic
make -j4
make test 
make install 

跑步很重要 make test 在安裝庫之前。 如果測試有錯誤,不要運行 make install 直到錯誤被糾正。

在下一步中,我們備份當前的二進製文件 openssl 然後我們添加 symlink 到新的。

mv /usr/bin/openssl /usr/bin/openssl-backup
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl

/usr/local/openssl/bin 執行 ldd 檢查依賴關係 openssl. 我們也可以檢查的版本 openssl. 命令 openssl version.

[root@north bin]# ldd openssl
	linux-vdso.so.1 =>  (0x00007ffd20bd7000)
	libssl.so.1.1 => /lib64/libssl.so.1.1 (0x00007fab09b62000)
	libcrypto.so.1.1 => /lib64/libcrypto.so.1.1 (0x00007fab09675000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007fab09471000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fab09255000)
	libc.so.6 => /lib64/libc.so.6 (0x00007fab08e87000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fab09df5000)
[root@north bin]# openssl version
OpenSSL 1.1.1p  21 Jun 2022

我們目前安裝了最新版本 OpenSSL 經久不衰 TLSv1.3. 我們可以檢查版本 TLS / SSL 書店支持 OpenSSL 按命令:

[root@north bin]# openssl ciphers -v | awk '{print $2}' | sort | uniq
SSLv3
TLSv1
TLSv1.2
TLSv1.3
[root@north bin]# 

這並不意味著在經理的幫助下託管的網站 VestaCP 他們將立即擁有 TLS 1.3.

雖然我們已經安裝 OpenSSL 1.1.1p, Nginx 是用老版本編譯的 OpenSSL 1.0.2k-fips.

[root@north bin]# nginx -V
nginx version: nginx/1.22.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
configure arguments: --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-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
[root@north bin]# openssl version
OpenSSL 1.1.1p  21 Jun 2022
[root@north bin]# 

2.為系統重新編譯Nginx VestaCP

這一步我們需要重新編譯 OpenSSL 已安裝的 Nginx 版本 在系統上 CentOS / VestaCP. 正如我上面所說,就我而言,它是關於 nginx/1.22.0. 由於我們正在談論一個具有 VestaCP 管理系統,在我們開始重新編譯之前,最好備份 nginx 配置文件。

備份系統上當前的 Nginx VestaCP

將目錄存檔並保存在服務器上的某個位置“/etc/nginx“和”/usr/local/vesta/nginx“。

跑步 nginx -V 並將現有模塊保存到文件中。

configure arguments: --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-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
你怎麼激活? TLSNGINX 上的 v1.3
如何激活 TLSNGINX 上的 v1.3

如何重新編譯 Nginx 以進行升級 OpenSSL / CentOS 7

我重複。 如果你有 VestaCP,下載您已經安裝的 Nginx 版本。 你可以找到所有帶有 Nginx 版本的檔案 nginx 網站.

cd /usr/src
wget https://nginx.org/download/nginx-1.22.0.tar.gz 
tar xvf nginx-1.22.0.tar.gz
cd nginx-1.22.0

我們重新編譯 nginx 模塊:

./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=/usr/src/openssl  \
--with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong  \
--param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC'  \
--with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
make -j4
make install

我們現在已經安裝了 Nginx 並使用最新版本編譯 OpenSSL 能夠承受 TLSv1.3。

[root@north bin]# nginx -V
nginx version: nginx/1.22.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.1.1p  21 Jun 2022
TLS SNI support enabled

*如果服務器上已經安裝了 nginx,則需要將其卸載。 編譯不適用於 nginx 升級。

如何在 VestaCP 上為網域啟用 TLSv1.3?

在文件中 /etc/nginx/nginx.conf 我們添加以下行:

ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';

在域級別,我更改了模板中的一些內容 VestaCP 並啟用 HTTP/2. 因此,當添加啟用了 Let's Encrypt 的新域 (example.com) 時,我有以下配置文件 SSL:

cat /home/vestacpuser/conf/web/example.com.nginx.ssl.conf 

server {
    listen      IP.IP.IP.IP:443 ssl http2;
    server_name example.com www.example.com;
    root        /home/vestacpuser/web/example.com/public_html;
    index       index.php index.html index.htm;
    access_log  /var/log/nginx/domains/example.com.log combined;
    access_log  /var/log/nginx/domains/example.com.bytes bytes;
    error_log   /var/log/nginx/domains/example.com.error.log error;

    ssl_certificate      /home/vestacpuser/conf/web/ssl.example.com.pem;
    ssl_certificate_key  /home/vestacpuser/conf/web/ssl.example.com.key;

....

ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';

在重啟 nginx 之前,最好先測試一下它的配置。

[root@north web]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@north web]# systemctl restart nginx

我希望本教程對您有所幫助,如果您遇到困難,請在評論中留下問題的詳細信息。

對技術充滿熱情,我很高興寫 StealthSettings.com 自 2006 年起。我在作業系統方面擁有豐富的經驗: macOS, Windows 對 Linux,而且還包括程式語言和部落格平台(WordPress)和線上商店(WooCommerce、Magento、PrestaShop)。

如何 » Linux » 如何在 NGINX 上啟用 TLSv1.3?VestaCP / CentOS 或 Ubuntu
發表評論