在Ubuntu上使用Apache部署SSL证书,可以按照以下步骤进行:
如果你还没有安装Apache,可以使用以下命令进行安装:
sudo apt update
sudo apt install apache2
你可以从Let’s Encrypt免费获取SSL证书。首先,确保你已经安装了Certbot:
sudo apt install certbot python3-certbot-apache
使用Certbot获取并安装SSL证书:
sudo certbot --apache
Certbot会引导你完成以下步骤:
Certbot会自动修改Apache的配置文件,使其支持HTTPS。你可以通过以下命令查看生成的配置文件:
sudo cat /etc/apache2/sites-available/yourdomain.com-le-ssl.conf
确保配置文件中包含以下内容:
<VirtualHost *:443>
ServerAdmin webmaster@yourdomain.com
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/yourdomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/yourdomain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
确保你的SSL站点配置文件已启用:
sudo a2ensite yourdomain.com-le-ssl.conf
重启Apache以应用更改:
sudo systemctl restart apache2
打开浏览器,访问https://yourdomain.com,你应该能看到一个绿色的锁图标,表示SSL证书已正确安装。
Let’s Encrypt的证书有效期为90天,Certbot会自动为你续期。你可以通过以下命令测试续期过程:
sudo certbot renew --dry-run
如果一切正常,Certbot会在证书到期前自动续期。
通过以上步骤,你就可以在Ubuntu上使用Apache成功部署SSL证书了。