Let's encrypt 自动签发SSL证书
2024-08-04
Let's encrypt 配置
在CentOS上使用Let's Encrypt签发SSL证书的步骤如下:
1. 安装Certbot客户端:
shell
sudo yum install epel-release
sudo yum install certbot
问题:阿里云的机器装不上
cd /etc/yum.repos.d/
rm -rf docker-ce.repo
2. 安装插件
shell
sudo yum install python3-certbot-nginx
很多教程绕过了这一步,可能报错:
The requested nginx plugin does not appear to be installed
3. 获取证书:
对于Apache服务器:
shell
sudo certbot --apache -d example.com -d www.example.com
对于Nginx服务器:
shell
sudo certbot --nginx -d example.com -d www.example.com
如果你想手动配置,可以使用:
shell
sudo certbot certonly
sudo certbot certonly --standalone -d example.com -d www.example.com
按照提示完成配置,包括输入邮箱地址和同意服务条款等。
证书获取成功后,Certbot会自动配置你的Web服务器。
4. 设置自动续期,及添加定时任务以自动续期:
shell
sudo certbot renew --dry-run
shell
echo "0 0,12 * * * root python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew -q" | sudo tee -a /etc/crontab > /dev/null
or:
5. 自动更新证书:
Let’s Encrypt 证书有效期为 90 天,建议设置自动更新。可以通过在 /etc/crontab 文件中添加以下条目实现自动更新:
shell
0 0 * * * certbot renew --quiet
这将设置 Certbot 每天检查并更新即将到期的证书。