注:本教程在Vultr VPS上测试通过,如需部署请前往Vultr.com
TLS 1.3是传输层安全性(TLS)协议的版本,该协议于2018年作为建议的标准发布于 RFC 8446。与以前的产品相比,它提供了安全性和性能方面的改进。
本指南将演示如何在FreeBSD 12上使用Apache Web服务器启用TLS 1.3。
要求
运行FreeBSD 12的Vultr Cloud Compute(VC2)实例。
有效的域名并正确配置 A
/AAAA
/CNAME
您的域的DNS记录。
有效的TLS证书。我们将从“加密”中获取一个。
Apache版本 2.4.36
或更高。
OpenSSL版本 1.1.1
或更高。
在你开始之前
检查FreeBSD版本。
uname -ro
# FreeBSD 12.0-RELEASE
确保您的FreeBSD系统是最新的。
freebsd-update fetch install
pkg update && pkg upgrade -y
如果系统上没有必要的软件包,请安装它们。
pkg install -y sudo vim unzip wget bash socat git
使用您的首选用户名创建一个新用户帐户(我们将使用 johndoe
)。
adduser
# Username: johndoe
# Full name: John Doe
# Uid (Leave empty for default):
# Login group [johndoe]:
# Login group is johndoe. Invite johndoe into other groups? []: wheel
# Login class [default]:
# Shell (sh csh tcsh nologin) [sh]: bash
# Home directory [/home/johndoe]:
# Home directory permissions (Leave empty for default):
# Use password-based authentication? [yes]:
# Use an empty password? (yes/no) [no]:
# Use a random password? (yes/no) [no]:
# Enter password: your_secure_password
# Enter password again: your_secure_password
# Lock out the account after creation? [no]:
# OK? (yes/no): yes
# Add another user? (yes/no): no
# Goodbye!
跑过 visudo
命令并取消注释 %wheel ALL=(ALL) ALL
行,以允许成员 wheel
组以执行任何命令。
visudo
# Uncomment by removing hash (#) sign
# %wheel ALL=(ALL) ALL
现在,使用以下命令切换到新创建的用户 su
。
su - johndoe
注意: 更换 johndoe
使用您的用户名。
设置时区。
sudo tzsetup
安装 acme.sh
客户端并从Let’s Encrypt获得TLS证书
安装 acme.sh
。
sudo pkg install -y acme.sh
检查版本。
acme.sh --version
# v2.7.9
为您的域获取RSA和ECDSA证书。
# RSA
sudo acme.sh --issue --standalone -d example.com --ocsp-must-staple --keylength 2048
# ECC/ECDSA
sudo 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 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 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的支持。 FreeBSD 12系统自带Apache和OpenSSL,它们均支持TLS 1.3,因此无需构建自定义版本。
通过下载并安装最新的Apache 2.4分支。 pkg
包裹经理。
sudo pkg install -y apache24
检查版本。
httpd -v
# Server version: Apache/2.4.38 (FreeBSD)
启动并启用Apache。
sudo sysrc apache24_enable="yes"
sudo service apache24 start
为TLS 1.3配置Apache
既然我们已经成功安装了Apache,我们就可以对其进行配置,以开始在服务器上使用TLS 1.3。
注意: 在FreeBSD中, mod_ssl
默认情况下,程序包和端口中都启用了模块
跑 sudo vim /usr/local/etc/apache24/httpd.conf
并通过取消注释包括SSL模块 LoadModule ssl_module libexec/apache24/mod_ssl.so
。
#LoadModule ssl_module libexec/apache24/mod_ssl.so
跑 sudo vim /usr/local/etc/apache24/Includes/example.com.conf
,并使用以下基本配置填充文件。
Listen 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"
保存文件并使用:+ W + Q退出。
检查配置。
sudo service apache24 configtest
重新加载Apache。
sudo service apache24 reload
通过Web浏览器中的HTTPS协议打开您的网站。要验证TLS 1.3,可以使用浏览器开发工具或SSL Labs服务。以下屏幕截图显示了运行TLS 1.3的Chrome的安全标签。
您已经在FreeBSD服务器上的Apache中成功启用了TLS 1.3。 TLS 1.3的最终版本已于2018年8月定义,因此没有更好的时间开始采用这项新技术。
注:本教程在Vultr VPS上测试通过,如需部署请前往Vultr.com