diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ecc101..c686930 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,11 @@ - SSL: 配置强加密套件(ECDHE+AESGCM/CHACHA20) - SSL: 删除不安全的 CloudFlare Origin 证书 +### 运维 +- 证书续期: 创建 deploy hook,续期后自动重载 nginx +- 证书续期: 创建 ACME webroot 目录(/var/www/html/.well-known/acme-challenge/) +- 文档: 记录 systemd timer 证书续期机制 + --- ## 2026-07-02 diff --git a/CLAUDE.md b/CLAUDE.md index 0956803..11bee57 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -44,14 +44,60 @@ nginx-proxy-ai 是 tlyq.ai 域名的统一入口,负责: ssh txjp "docker exec nginx-ai nginx -s reload" ``` -### 证书续期检查 +### 证书续期机制 + +证书续期通过 **systemd timer** 自动管理,无需人工干预。 + +#### 工作原理 + +``` +systemd timer (snap.certbot.renew.timer) + ↓ 每天 01:30 和 22:32 触发 +systemd service (snap.certbot.renew.service) + ↓ 执行 +certbot renew --timer="00:00~24:00/2" + ↓ 续期成功后 +deploy hook → docker exec nginx-ai nginx -s reload +``` + +#### 关键文件 + +| 组件 | 路径 | 说明 | +|------|------|------| +| Timer | `/etc/systemd/system/snap.certbot.renew.timer` | 定时触发器 | +| Service | `/etc/systemd/system/snap.certbot.renew.service` | 执行续期的服务 | +| Hook | `/etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh` | 续期后重载 nginx | + +#### Timer 配置 + +```ini +[Timer] +OnCalendar=*-*-* 01:30 # 每天 01:30 +OnCalendar=*-*-* 22:32 # 每天 22:32 +``` + +每天检查两次,距离到期 < 30 天时自动续期。 + +#### 常用管理命令 ```bash +# 查看定时器状态 +ssh txjp "systemctl status snap.certbot.renew.timer" + +# 查看下次运行时间 +ssh txjp "systemctl list-timers snap.certbot.renew.timer" + +# 手动触发续期 +ssh txjp "systemctl start snap.certbot.renew.service" + +# 查看续期日志 +ssh txjp "journalctl -u snap.certbot.renew.service --since '1 hour ago'" + # 检查证书有效期 ssh txjp "openssl x509 -in /etc/letsencrypt/live/www.tlyq.ai/fullchain.pem -noout -dates" -# 检查续期定时器 -ssh txjp "systemctl list-timers | grep certbot" +# 测试续期(不实际续期) +ssh txjp "certbot renew --dry-run" ``` ## 文件结构 diff --git a/README.md b/README.md index af6bcdf..f1b109f 100644 --- a/README.md +++ b/README.md @@ -44,16 +44,27 @@ CloudFlare Origin 证书是自签名证书,浏览器不信任,会导致 SSL ### 证书续期 -Let's Encrypt 证书有效期 90 天,需自动续期: +证书续期通过 **systemd timer** 自动管理,每天检查两次(01:30 和 22:32),距离到期 < 30 天时自动续期。 ```bash -# 检查续期定时器 -systemctl list-timers | grep certbot +# 查看定时器状态 +systemctl status snap.certbot.renew.timer -# 手动续期 -certbot renew --deploy-hook "docker exec nginx-ai nginx -s reload" +# 查看下次运行时间 +systemctl list-timers snap.certbot.renew.timer + +# 手动触发续期 +systemctl start snap.certbot.renew.service + +# 查看续期日志 +journalctl -u snap.certbot.renew.service --since "1 hour ago" + +# 测试续期(不实际续期) +certbot renew --dry-run ``` +续期成功后自动执行 deploy hook 重载 nginx,无需人工干预。 + ### 新增站点证书 1. 使用 certbot 申请证书: