Let’s Encrypt 是一个免费的 SSL/TLS 证书提供商,可让您轻松保护您的网站。 这是如何确保安全 Apache 在 Debian 10 上使用 Let’s Encrypt。
如何保护 Apache 在 Debian 10 上使用 Let’s Encrypt
以下是确保安全的步骤 Apache 在 Debian 10、Debian 9 和 Ubuntu Linux 上使用 Let’s Encrypt。
1.安装Certbot
Let’s Encrypt 提供了一个名为 Certbot 的自动化工具,可以自动获取和更新 Let’s Encrypt SSL 证书。
打开终端并运行以下命令
sudo apt update sudo apt install certbot
奖励阅读:如何设置 CORS Apache
2. 设置 SSL 配置 Apache
Certbot 需要找到与您为其获取 SSL 证书的域匹配的 ServerName 指令。 假设您想为 example.com 域获取 SSL 证书。 打开您的域 example.com 的虚拟主机配置文件
$ sudo vi /etc/apache2/sites-available/example.com.conf
确保 ServerName 指令指向您的域 (example.com)
ServerName example.com
重新开始 Apache
$ sudo systemctl reload apache2
在继续之前,请确保您已在防火墙中允许端口 443 的 HTTPS 流量。
奖励阅读:如何安装 Apache Ubuntu 中的 mod_security
3.获取SSL证书
运行以下命令从包含虚拟主机文件 (/etc/apache2/sites-available/) 的同一目录中获取 example.com 和 www.example.com 的单个 SSL 证书
$ sudo certbot certonly --agree-tos --email [email protected] -d example.com -d www.example.com
在上面的命令中,替换 [email protected] 与您的网站管理员的电子邮件地址。
certbot 将开始与 Let’s Encrypt 服务器通信以获取 SSL 证书,在它运行安全质询以验证您实际上控制了您为其请求 SSL 证书的域之后。
如果 Let’s Encrypt 获得 SSL 证书,您将看到以下消息
IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/example.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/example.com/privkey.pem Your cert will expire on 2018-12-04. To obtain a new or tweaked version of this certificate in the future, simply run certbot again with the "certonly" option. To non-interactively renew *all* of your certificates, run "certbot renew" - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le
奖励阅读:如何安装 SSL 证书 Apache 视窗
4. 更新虚拟主机配置文件
上述消息包含您的 SSL 证书和密钥文件的路径。 打开虚拟主机配置文件以添加这些路径。
$ sudo vi /etc/apache2/sites-available/example.com.conf
在 行之前的 VirtualHost * : 443 标记中添加以下行。
SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
你的 VirtualHost 块看起来像这样
<VirtualHost *:443> ServerName example.com ServerAlias www.example.com ... SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem ... </VirtualHost>
奖励阅读:如何在 Linux 中为 SSL 证书生成 CSR
5. 测试 Apache 配置和重启服务器
运行以下命令进行测试 Apache 服务器配置
$ sudo apachectl configtest
如果您没有看到任何错误,请重新启动 Apache 网络服务器。
$ sudo service apache2 restart
现在您已经安装了 Let’s Encrypt SSL 证书 Apache 网络服务器。 打开浏览器并访问 https:// 您域的版本(例如 https://www.example.com)。
您将在浏览器地址栏中的 URL 旁边看到一个锁定符号,表明您网站的 SSL/TLS 证书工作正常。
希望现在您可以保护 Apache 使用 Let’s Encrypt SSL 证书 Apache 适用于 Debian/Ubuntu 以及其他 Linux 系统。
CodePre 可以在几分钟内轻松可视化数据,并在实时仪表板中进行监控。 今天就试试吧!