在Ubuntu上为Apache启用SSL加密,你需要遵循以下步骤:
-
安装Apache和SSL模块: 打开终端,运行以下命令来安装Apache和SSL模块:
sudo apt update sudo apt install apache2 sudo a2enmod ssl
-
获取SSL证书: 你可以从Let’s Encrypt免费获取SSL证书。要安装Certbot并获取证书,请运行以下命令:
sudo apt install certbot python3-certbot-apache sudo certbot --apache -d yourdomain.com -d www.yourdomain.com
将
yourdomain.com
和www.yourdomain.com
替换为你的域名。Certbot将自动配置Apache以使用SSL证书。 -
重启Apache: 证书安装完成后,重启Apache以应用更改:
sudo systemctl restart apache2
-
验证SSL配置: 在浏览器中输入你的域名,然后点击地址栏左侧的锁图标。如果一切正常,你应该能看到一个绿色的锁,表示你的网站已成功启用SSL加密。
-
(可选)自动更新证书: Let’s Encrypt证书有效期为90天。为了确保证书始终有效,你可以设置Certbot自动更新证书。运行以下命令:
sudo systemctl enable certbot.timer sudo systemctl start certbot.timer
现在,你的Ubuntu Apache服务器已启用SSL加密。