在Debian上使用Let’s Encrypt SSL证书可以按照以下步骤进行:
Certbot是Let’s Encrypt的官方客户端,用于自动化获取和续订SSL证书。
sudo apt update
sudo apt install certbot python3-certbot-nginx
如果你使用的是Apache而不是Nginx,可以安装python3-certbot-apache
:
sudo apt install python3-certbot-apache
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
sudo certbot --apache -d yourdomain.com -d www.yourdomain.com
在运行上述命令时,Certbot会自动配置你的Web服务器(Nginx或Apache)以使用SSL,并将证书和私钥文件放置在适当的位置。
Certbot会自动验证你的域名是否可以访问。如果一切正常,它会完成证书的颁发过程。
Let’s Encrypt的证书有效期为90天,因此需要定期续订。Certbot可以自动续订证书。
首先,编辑Certbot的定时任务:
sudo crontab -e
添加以下行以每天运行一次续订检查:
0 */24 * * * certbot renew --post-hook "systemctl reload nginx"
如果你使用的是Apache,将systemctl reload nginx
替换为systemctl reload apache2
。
确保你的防火墙允许HTTPS流量(端口443)。
sudo ufw allow 'Nginx Full'
或者如果你使用的是Apache:
sudo ufw allow 'Apache Full'
你可以使用以下命令测试你的SSL配置是否正确:
sudo openssl s_client -connect yourdomain.com:443
这将显示你的SSL证书的详细信息。
如果你还没有将HTTP流量重定向到HTTPS,可以使用Certbot的重定向插件来完成这一任务。
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com --redirect
sudo certbot --apache -d yourdomain.com -d www.yourdomain.com --redirect
完成这些步骤后,你的Debian服务器应该已经成功配置了Let’s Encrypt SSL证书,并且可以自动续订。