安装 EPEL 源
1 | yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm |
安装 mod_ssl 模块
1 | yum install mod_ssl |
安装 Certbot 客户端
从 EPEL 存储库安装 Certbot 客户端:
1 | yum install python-certbot-apache |
虚拟主机配置
在80端口上配置虚拟主机,例如:
1 | <VirtualHost *:80> |
域名解析
添加 A 记录,将域名指向 IP 地址,如果使用 CDN 服务,例如 Cloudflare,则需将代理状态设置为 仅限 DNS
,SSL 证书配置完成后可以改为 已代理
。
获取并配置 SSL 证书
替换以下命令中的 example.com
,为域名配置 SSL 证书,此过程需要输入邮箱地址。
1 | certbot --apache -d example.com |
自动续订证书
Let’s Encrypt 的免费 SSL 证书的有效期为90天,所以需要定期进行续订。编辑 crontab:
1 | crontab -e |
添加以下定时任务。此任务将在每月1日的中午12点自动执行 certbot renew
命令,尝试续订30天内到期的证书并将输出存入 /var/log/ssl-renew.log
文件。
1 | 0 12 1 * * /usr/bin/certbot renew >> /var/log/ssl-renew.log |
开放端口
开放 443
端口:
1 | firewall-cmd --zone=public --add-port=443/tcp --permanent |
重新加载 firewalld,使规则立即生效。
1 | firewall-cmd --reload |
然后在浏览器打开 https://域名/
,如果地址栏出现锁的图标说明 SSL 证书安装成功。