如何在Debian 10上的Apache中启用TLS 1.3

注:本教程在Vultr VPS上测试通过,如需部署请前往Vultr.com

TLS 1.3是传输层安全性(TLS)协议的一个版本,该协议于2018年作为RFC 8446中的提议标准发布。它比以前的版本提供了安全性和性能方面的改进。

本指南将演示如何使用Debian 10上的Apache Web服务器启用TLS 1.3。

要求

运行Debian 10(Buster)的Vultr Cloud Compute(VC2)实例。
有效的域名并正确配置 A/AAAA/CNAME 您的域的DNS记录。
有效的TLS证书。我们将从“加密”中获取一个。
Apache版本 2.4.36 或更高。
OpenSSL版本 1.1.1 或更高。

在你开始之前

检查Debian版本。

lsb_release -ds
# Debian GNU/Linux 10 (buster)

创建一个新的 non-root 用户帐户 sudo 访问并切换到它。

adduser johndoe --gecos "John Doe"
usermod -aG sudo johndoe
su - johndoe

注意:更换 johndoe 使用您的用户名。

设置时区。

sudo dpkg-reconfigure tzdata

确保您的系统是最新的。

sudo apt update && sudo apt upgrade -y

安装所需的软件包。

sudo apt install -y zip unzip curl wget git socat

安装 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 [email protected]
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/example.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
纠错码/ECDSA/etc/letsencrypt/example.com_ecc

安装Apache

Apache在版本2.4.36中添加了对TLS 1.3的支持。 Debian 10系统附带了支持TLS 1.3的Apache和OpenSSL,因此无需构建自定义版本。

通过下载并安装最新的Apache 2.4分支。 apt 包裹经理。

sudo apt install -y apache2

检查版本。

sudo apache2 -v
# Server version: Apache/2.4.38 (Debian)
# Server built:   2019-04-07T18:15:40

为TLS 1.3配置Apache

既然我们已经成功安装了Apache,我们就可以对其进行配置,以开始在服务器上使用TLS 1.3。

首先,启用SSL模块。

sudo a2enmod ssl

重新启动Apache。

sudo systemctl restart apache2

sudo vim /etc/apache2/sites-available/example.com.conf,并使用以下基本配置填充文件。


  
    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"

  

保存文件并退出。

通过将新的配置文件链接到 sites-enabled 目录。

sudo a2ensite example.com.conf

检查配置。

sudo apachectl configtest

重新加载Apache。

sudo systemctl reload apache2

通过Web浏览器中的HTTPS协议打开您的网站。要验证TLS 1.3,可以使用浏览器开发工具或SSL Labs服务。以下屏幕截图显示了运行TLS 1.3的Chrome的安全标签。

您已在Debian 10服务器上的Apache中成功启用TLS 1.3。 TLS 1.3的最终版本已于2018年8月定义,因此没有更好的时间开始采用这项新技术。

注:本教程在Vultr VPS上测试通过,如需部署请前往Vultr.com