如何在运行Apache Web服务器的CentOS 7上安装“让我们加密SSL”

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

介绍

在本教程中,您将学习在Apache Web服务器上安装TLS / SSL证书的过程。完成后,服务器和客户端之间的所有流量都将被加密。这是保护电子商务站点和其他在线金融服务的标准做法。让我们加密是实现免费SSL的先驱,在这种情况下,它将用作证书提供者。

先决条件

在开始本指南之前,您需要满足以下条件:

SSH根访问CentOS 7 VPS
正确配置了域和虚拟主机的Apache Web服务器
非root用户sudo用户

安装相关模块

要安装certbot,您将必须安装EPEL存储库,因为默认情况下它不可用, mod_ssl 要让Apache识别加密,还需要:

sudo yum install -y epel-release mod_ssl

下载“让我们加密”客户端

接下来,您将从EPEL存储库安装certbot客户端:

sudo yum install python-certbot-apache

获取并配置SSL证书

Certbot将非常轻松地处理SSL证书管理。它将为提供的域生成一个新证书作为参数。

在这种情况下, example.com 将用作将证书颁发到的域:

sudo certbot --apache -d example.com

如果要为多个域或子域生成SSL,请使用以下命令:

sudo certbot --apache -d example.com -d www.example.com

注意: 在此示例中,第一个域应该是您的基本域: example.com

安装证书时,您将收到分步指南,该指南将允许您自定义证书详细信息。您将可以在强迫之间进行选择 HTTPS 或离开 HTTP 作为默认协议。出于安全原因,还需要提供电子邮件地址。

安装完成后,您将收到类似的消息:

IMPORTANT NOTES:
- If you lose your account credentials, you can recover through
emails sent to [email protected].
- Congratulations! Your certificate and chain have been saved at
/etc/letsencrypt/live/example.com/fullchain.pem. Your cert
will expire on 2019-04-21. To obtain a new version of the
certificate in the future, simply run Let's Encrypt again.
- Your account credentials have been saved in your Let's Encrypt
configuration directory at / etc / letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also have certificates and private keys obtained by Let's
Encrypt so regular backups of this folder is ideal.
- If you like Let's Encrypt, please consider supporting our work by:

配置自动证书续订

让我们加密证书的有效期为90天。建议您在60天内进行续订,以免出现任何问题。为此,certbot将协助我们执行您的续订命令。它将验证证书距离有效期少于30天:

sudo certbot renew

如果安装的证书是最新证书,certbot将仅验证其到期日期:

Processing  /etc/letsencrypt/renewal/example.com.conf
The following certs are not due for renewal yet:
    /etc/letsencrypt/live/example.com/fullchain.pem (skipped)
No renewals were attempted.

要自动执行此续订过程,可以设置一个cronjob。首先,打开crontab:

sudo crontab -e

可以安全地安排此工作在每个星期一的午夜运行:

0 0 * * 1 / usr / bin / certbot renew >> /var/log/sslrenew.log

脚本的输出将通过管道传输到 /var/log/sslrenew.log 文件。

结论

您只需通过实施免费的SSL证书来保护Apache Web服务器。从现在开始,服务器和客户端之间的所有流量都被加密。

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