TLS 1.3是传输层安全( TLS ) 协议的最新版本,它基于现有的 1.2 规范和适当的IETF 标准:RFC 8446。与前代产品相比,它提供了更强的安全性和更高的性能改进。
在本文中,我们将向您展示如何获取有效的 TLS 证书并在Apache或Nginx Web 服务器上托管的域上启用最新的TLS 1.3版本协议的分步指南。
要求:
- Apache 版本 2.4.37 或更高版本。
- Nginx 版本 1.13.0 或更高版本。
- OpenSSL 版本 1.1.1 或更高版本。
- 具有正确配置的 DNS 记录的有效域名。
- 有效的 TLS 证书。
从 Let's Encrypt 安装 TLS 证书
要从Let's Encrypt获取免费的SSL 证书,您需要在 Linux 系统上安装Acme.sh客户端和一些所需的软件包,如图所示。
# apt install -y socat git [在 Debian/Ubuntu 上] # dnf install -y socat git [在 RHEL/CentOS/Fedora 上] #mkdir /etc/letsencrypt # git 克隆 https://github.com/Neilpang/acme.sh.git # cd acme.sh # ./acme.sh --install --home /etc/letsencrypt --accountemail your_email@example.com # 光盘 ~ #/etc/letsencrypt/acme.sh --issue --standalone --home /etc/letsencrypt -d example.com --ocsp-must-staple --keylength 2048 # /etc/letsencrypt/acme.sh --issue --standalone --home /etc/letsencrypt -d example.com --ocsp-must-staple --keylength ec-256
注意:将example.com
上述命令替换为您的真实域名。
安装 SSL 证书后,您可以进一步在您的域上启用TLS 1.3,如下所述。
在 Nginx 上启用 TLS 1.3
正如我在上面的要求中提到的,从Nginx 1.13版本开始支持TLS 1.3。如果您运行的是较旧的 Nginx 版本,则需要先升级到最新版本。
# apt安装nginx # 百胜安装 nginx
检查Nginx版本和编译 Nginx 的OpenSSL版本(确保nginx版本至少为1.14且openssl版本至少为1.1.1)。
# nginx -V
样本输出
nginx 版本:nginx/1.14.1 由 gcc 8.2.1 20180905(红帽 8.2.1-3)(GCC)构建 使用OpenSSL 1.1.1 FIPS 构建 2018 年 9 月 11 日 启用 TLS SNI 支持 ....
现在启动、启用并验证 nginx 安装。
# systemctl 启动 nginx.service # systemctl 启用 nginx.service # systemctl 状态 nginx.service
Now open the nginx vhost configuration /etc/nginx/conf.d/example.com.conf
file using your favorite editor.
# vi /etc/nginx/conf.d/example.com.conf
and locate ssl_protocols
directive and append TLSv1.3 at the end of the line as shown below
server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name example.com; # RSA ssl_certificate /etc/letsencrypt/example.com/fullchain.cer; ssl_certificate_key /etc/letsencrypt/example.com/example.com.key; # ECDSA ssl_certificate /etc/letsencrypt/example.com_ecc/fullchain.cer; ssl_certificate_key /etc/letsencrypt/example.com_ecc/example.com.key; ssl_protocols TLSv1.2 TLSv1.3; 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'; ssl_prefer_server_ciphers on; }
Finally, verify the configuration and reload Nginx.
# nginx -t # systemctl reload nginx.service
Enable TLS 1.3 in Apache
Beginning from Apache 2.4.37, you can take advantage of TLS 1.3. If you are running the older version of Apache, you need to first upgrade to the latest version.
# apt install apache2 # yum install httpd
Once installed, you can verify the Apache and the OpenSSL version against which Apache was compiled.
# httpd -V # openssl version
Now start, enable and verify the nginx installation.
-------------- On Debian/Ubuntu -------------- # systemctl start apache2.service # systemctl enable apache2.service # systemctl status apache2.service -------------- On RHEL/CentOS/Fedora -------------- # systemctl start httpd.service # systemctl enable httpd.service # systemctl status httpd.service
Now open the Apache virtual host configuration file using your favorite editor.
# vi /etc/httpd/conf.d/vhost.conf OR # vi /etc/apache2/apache2.conf
and locate ssl_protocols
directive and append TLSv1.3 at the end of the line as shown below.
<VirtualHost *:443> SSLEngine On # RSA ssl_certificate /etc/letsencrypt/example.com/fullchain.cer; ssl_certificate_key /etc/letsencrypt/example.com/example.com.key; # ECDSA ssl_certificate /etc/letsencrypt/example.com_ecc/fullchain.cer; ssl_certificate_key /etc/letsencrypt/example.com_ecc/example.com.key; ssl_protocols TLSv1.2 TLSv1.3 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'; ssl_prefer_server_ciphers on; SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem 服务器管理员 admin@example.com 服务器名称 www.example.com 服务器别名 example.com #DocumentRoot /data/httpd/htdocs/example.com/ DocumentRoot /data/httpd/htdocs/example_hueman/ # 日志文件位置 日志级别警告 错误日志 /var/log/httpd/example.com/httpserror.log CustomLog“|/usr/sbin/rotatelogs /var/log/httpd/example.com/httpsaccess.log.%Y-%m-%d 86400”组合 </虚拟主机>
最后,验证配置并重新加载 Apache。
-------------- 在 Debian/Ubuntu 上 -------------- #apache2-t # systemctl 重新加载 apache2.service -------------- 在 RHEL/CentOS/Fedora 上 -------------- # httpd-t # systemctl 重新加载 httpd.service
验证站点正在使用 TLS 1.3
通过网络服务器进行配置后,您可以使用Chrome 70+版本上的 Chrome 浏览器开发工具检查您的网站是否通过TLS 1.3协议进行握手。
![](https://www.alaica.com/wp-content/uploads/linux-581.png)
就这样。您已成功在 Apache 或 Nginx Web 服务器上托管的域上启用TLS 1.3协议。如果您对本文有任何疑问,请随时在下面的评论部分提问。