在Ubuntu上启用Apache2的SSL,你需要遵循以下步骤:
安装Apache2和SSL模块:打开终端,运行以下命令来安装Apache2和SSL模块:
sudo apt updatesudo apt install apache2sudo a2enmod ssl
获取SSL证书:你可以从Let’s Encrypt免费获取SSL证书。要安装Certbot并获取证书,请运行以下命令:
sudo apt install certbot python3-certbot-apachesudo certbot --apache -d yourdomain.com -d www.yourdomain.com
将yourdomain.com
和www.yourdomain.com
替换为你的域名。Certbot将自动配置Apache2以使用SSL,并创建一个新的SSL证书。
重启Apache2:证书安装完成后,重启Apache2以应用更改:
sudo systemctl restart apache2
验证SSL配置:在浏览器中访问https://yourdomain.com
(将yourdomain.com
替换为你的域名)。你应该看到一个绿色的锁图标,表示你的网站已成功启用SSL。
(可选)自动更新证书:Let’s Encrypt证书有效期为90天。为了自动更新证书,你可以运行以下命令:
sudo certbot renew --dry-run
如果一切正常,Certbot将自动更新证书。你还可以设置一个cron任务来定期检查并更新证书。
现在,你的Ubuntu服务器上的Apache2已经启用了SSL,你的网站可以通过HTTPS安全访问了。