TLS 1.3是传输层安全(TLS)协议的一个版本,于2018年在RFC 8446中作为一个建议标准发布。与之前的版本相比,它提供了安全性和性能方面的改进。
本文将介绍如何在CentOS 8上使用Apache webserver启用TLS 1.3。
在开始之前我们需要先检查CentOS版本。
cat /etc/centos-release
# CentOS Linux release 8.0.1905 (Core)
使用sudo访问创建一个新的no-root用户帐户并切换到它。
useradd -c "John Doe" johndoe && passwd johndoe
usermod -aG wheel johndoe
su - johndoe
注意:将johndoe替换为您的用户名。
设置时区。
timedatectl list-timezones
sudo timedatectl set-timezone 'Region/City'
确保您的系统是最新的。
sudo yum update
安装所需的软件包。
sudo yum install -y socat git
禁用SELinux和防火墙。
sudo setenforce 0 ; sudo systemctl stop firewalld ; sudo systemctl disable firewalld
安装acme.sh客户端并从Let's Encrypt获得TLS证书
安装acme.sh
sudo mkdir /etc/letsencrypt
git clone https://github.com/Neilpang/acme.sh.git
cd acme.sh
sudo ./acme.sh --install --home /etc/letsencrypt --accountemail your_email@example.com
cd ~
source ~/.bashrc
检查版本。
/etc/letsencrypt/acme.sh --version
# v2.8.2
获取您的域的RSA和ECDSA证书。
# RSA
sudo /etc/letsencrypt/acme.sh --issue --standalone -d example.com --ocsp-must-staple --keylength 2048
# ECC/ECDSA
sudo /etc/letsencrypt/acme.sh --issue --standalone -d example.com --ocsp-must-staple --keylength ec-256
注意:在命令中用您的域名替换example.com。
创建合适的目录来存储证书和密钥。我们将使用/etc/letsencrypt。
sudo mkdir -p /etc/letsencrypt/www.cnsugarhosts.com
sudo mkdir -p /etc/letsencrypt/example.com_ecc
安装证书并将其复制到/etc/letsencrypt。
# RSA
sudo /etc/letsencrypt/acme.sh --install-cert -d example.com --cert-file /etc/letsencrypt/example.com/cert.pem --key-file /etc/letsencrypt/example.com/private.key --fullchain-file /etc/letsencrypt/example.com/fullchain.pem
# ECC/ECDSA
sudo /etc/letsencrypt/acme.sh --install-cert -d example.com --ecc --cert-file /etc/letsencrypt/example.com_ecc/cert.pem --key-file /etc/letsencrypt/example.com_ecc/private.key --fullchain-file /etc/letsencrypt/example.com_ecc/fullchain.pem
运行上述命令后,您的证书和密钥将位于以下位置:
RSA: /etc/letsencrypt / example.com
ECC / ECDSA: /etc/letsencrypt / example.com_ecc
安装Apache
Apache在2.4.36版本中增加了对TLS 1.3的支持。CentOS 8系统附带Apache和OpenSSL,它们支持TLS 1.3开箱即用,因此不需要构建自定义版本。
通过yum包管理器下载并安装最新的2.4版Apache及其用于SSL的模块。
sudo yum install -y httpd mod_ssl
检查版本
sudo httpd -v
# Server version: Apache/2.4.37 (centos)
# Server built: Jul 30 2019 19:56:12
启动并启用Apache。
sudo systemctl start httpd.service
sudo systemctl enable httpd.service
为TLS 1.3配置Apache
现在我们已经成功地安装了Apache,我们已经准备好将其配置为在服务器上开始使用TLS 1.3。
运行sudo vim /etc/httpd/ con.d /example.com.conf,并使用以下基本配置填充该文件。
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName example.com
SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
# RSA
SSLCertificateFile "/etc/letsencrypt/example.com/fullchain.pem"
SSLCertificateKeyFile "/etc/letsencrypt/example.com/private.key"
# ECC
SSLCertificateFile "/etc/letsencrypt/example.com_ecc/fullchain.pem"
SSLCertificateKeyFile "/etc/letsencrypt/example.com_ecc/private.key"
</VirtualHost>
</IfModule>
保存文件并使用 :+W+Q退出。
检查配置。
sudo apachectl configtest
重新加载Apache以激活新配置。
sudo systemctl reload httpd.service
在web浏览器中通过HTTPS协议打开站点。要验证TLS 1.3,可以使用浏览器开发工具或SSL实验室服务。下面的截图显示了Chrome的安全标签与TLS 1.3的行动。
至此成功地在CentOS 8服务器上的Apache中启用了TLS 1.3。TLS 1.3的最终版本是在2018年8月定义的,所以现在是开始采用这项新技术的最佳时机。
联系客服