在Ubuntu上启用Apache2的SSL,你需要遵循以下步骤:
sudo apt update
sudo apt install apache2
sudo apt install certbot python3-certbot-apache
sudo certbot --apache
Certbot将提示你输入电子邮件地址、同意服务条款以及选择证书存储位置。完成这些步骤后,Certbot将自动配置Apache2以使用SSL。
Certbot将为你生成一个名为/etc/letsencrypt/options-ssl-apache.conf
的文件,其中包含一些推荐的SSL设置。你可以将这些设置合并到你的主Apache配置文件(通常是/etc/apache2/apache2.conf
或/etc/apache2/sites-available/000-default.conf
)中。
编辑你的Apache配置文件,确保包含以下内容:
Include /etc/letsencrypt/options-ssl-apache.conf
保存并关闭配置文件。
重启Apache2以应用更改:
sudo systemctl restart apache2
现在,你的网站应该已经通过HTTPS提供服务。你可以通过访问https://yourdomain.com
来验证这一点。如果一切正常,浏览器将显示一个绿色的锁图标,表示连接已加密。
请注意,Let’s Encrypt证书的有效期为90天。为了确保证书始终有效,你可以使用Certbot的自动续订功能。Certbot将每天检查证书的有效期,并在证书即将过期时自动续订。