Certbot自动续费Let‘s Encrypt证书

流程:Let's Encrypt会进行ca验证是否属于你的域名

使用 --webroot 模式会在 /var/www/example 中创建 .well-known 文件夹,这个文件夹里面包含了一些验证文件,certbot 会通过访问 example.com/.well-known/acme-challenge 来验证你的域名是否绑定的这个服务器。这个命令在大多数情况下都可以满足需求,

可以看下面的连接进行查看参考下,然后我这边就是可能是这个服务器做了什么限制,所以我采用dns解析的方案
连接

一、安装

shell 复制代码
# 安装 Certbot + 阿里云 DNS 插件 其他dns请看其他dns的方案问ai 
sudo apt update
sudo apt install -y certbot python3-pip
sudo pip3 install certbot-dns-aliyun

二、配置

shell 复制代码
sudo mkdir -p /etc/letsencrypt
sudo vim /etc/letsencrypt/aliyun.ini

写入(替换成你的 Key):

shell 复制代码
dns_aliyun_access_key = LTAI5xxxxxx
dns_aliyun_access_key_secret = qomUxxxxxx

必须改权限(防止泄露):

shell 复制代码
sudo chmod 600 /etc/letsencrypt/aliyun.ini

三、生成配置

-d xxx.com -d www.xxx.com是你的域名,生成成功后/etc/letsencrypt/live/xxx.com/证书的目录

shell 复制代码
sudo certbot certonly \
  --authenticator dns-aliyun \
  --dns-aliyun-credentials /etc/letsencrypt/aliyun.ini \
  --dns-aliyun-propagation-seconds 60 \
  -d xxx.com -d www.xxx.com

四、自动续费(关键)

1、测试自动续费

shell 复制代码
sudo certbot renew --dry-run

看到 Congratulations, all simulated renewals succeeded 即正常。

2、设置定时任务自动续费(自动续费后需要将证书替换docker里面,内容会变化)

shell 复制代码
sudo crontab -e

添加(每周一凌晨 3 点检查):

shell 复制代码
0 3 * * * /usr/bin/certbot renew --quiet

或者配置定时任务(自动续期 + 重载 Nginx)

shell 复制代码
0 3 * * 1 /usr/bin/certbot renew --quiet --deploy-hook "systemctl reload nginx"

--quiet:静默,只在出错时输出。

--deploy-hook:续期成功后自动重载 Nginx。

五、应急手动处理

shell 复制代码
# 立即检查并续期(到期前才会执行)
sudo certbot renew
# 强制立即重签(测试用)
sudo certbot renew --force-renewal
相关推荐
略懂而已4 天前
安装SSL后网站速度变慢?
网络·网络协议·ssl
qq_452396237 天前
第十篇:《Kafka 安全加固:SASL、SSL、ACL 与多租户隔离》
安全·kafka·ssl
达梦产品与服务12 天前
SQLark V4.2 更新 | 新增TiDB、SSL安全连接、数据字典、清空/截断表等40+项功能已上线!
数据库·安全·tidb·ssl
云-缩影15 天前
拆解微信小程序后端架构:ECS、RDS、SSL 和 VPC 怎么配合
微信小程序·架构·ssl
DevLoom_19 天前
macOS 命令行 curl/git 报 SSL 证书错误?eMudhra 事件完整修复指南
git·macos·ssl
zxanz119 天前
国密 SM2 SSL 证书和国际证书怎么选,一文理清差异
https·ssl
RacentCLM20 天前
证书即服务CaaS:从申请、续期到部署的自动化链路拆解
运维·数据库·自动化·ssl
HoneyMoose24 天前
Ubuntu Apache 配置多站点提示 SSL 错误
ubuntu·apache·ssl
AnTrust24 天前
代码签名证书品牌价格对比:DigiCert、GlobalSign、Comodo、Certum怎么选
运维·服务器·ssl
zxanz125 天前
免费 SSL 证书的隐性成本:续期压力、稳定性与商业风险评估
网络·网络协议·ssl