--- name: session-20260611-2 description: 2026-06-11 第2次会话 — Let's Encrypt证书管理全栈实现 metadata: type: session date: 2026-06-11 sessionNumber: 2 startTime: 2026-06-11T22:00+08:00 endTime: 2026-06-11T22:40+08:00 --- # 2026-06-11 第2次会话 ## 会话摘要 为 zgitm.com(阿里云购买域名)实现 Let's Encrypt DNS-01 证书管理全栈功能: - acme.sh + 阿里云 DNS API 自动签发/续期 - 系统内置域名保护(不可在页面创建/修改/删除) - 证书管理独立页面(签发/续期/通知设置) - Java 端 @Scheduled 定时任务,到期前15天每日10点发邮件提醒,连续15天 - 邮件通过 Mokee Gateway 对外开放 API 发送(systemCode: nginxServer) ## 关键操作 ### 数据库变更 - `certificates` 表新增字段: cert_type, notify_email, notify_enabled, notify_days_before, last_renew_time, renew_log - 新建 `cert_notify_log` 表: 记录通知发送日志 - 插入 zgitm.com / www.zgitm.com 为 letsencrypt 类型证书 ### 服务器 (10.1.1.160) - 安装 acme.sh v3.1.4(GitHub clone,绕过 get.acme.sh 被墙) - 设置默认 CA: Let's Encrypt - 阿里云 AccessKey 配置在 /root/.bashrc: Ali_Key / Ali_Secret - 正式签发 zgitm.com 和 www.zgitm.com Let's Encrypt 证书 - 证书安装至 /etc/nginx/ssl/{domain}.pem + .key - 到期时间: 2026-09-09,自动续期: 2026-08-10 ### Python API - `ssl_service.py`: +约120行,LE_DOMAINS 列表,ensure_le_certificate(),renew_le_certificate(),get_le_cert_info() - `app.py`: 新增 4 个证书管理端点 + add_rule 中系统域名拦截 ### Java 后端(新建/修改共8个文件) - `Certificate.java`: 新实体 - `CertificateRepository.java`: JPA Repository - `CertificateService.java`: CRUD + 签发 + 续期 + 通知配置 - `CertificateController.java`: /api/certificates REST API - `CertNotifyScheduler.java`: @Scheduled(cron="0 0 10 * * ?") 每天10点检查+发邮件 - `PythonApiClient.java`: +4个证书API方法,签发/续期用 certRestTemplate(210s超时) - `ForwardingRuleService.java`: 系统域名保护(增删改拦截) - `RestTemplateConfig.java`: 新增 certRestTemplate Bean - `application.yml`: +gateway 配置段 ### 前端(新建/修改共5个文件) - `CertManagement.vue`: 证书管理页面(列表/签发/续期/通知设置) - `router/index.js`: +/cert-management 路由 - `MainLayout.vue`: +SSL证书管理菜单(Key图标) - `nginxApi.js`: +5个证书API方法 - `NginxForwarding.vue`: 系统域名保护(操作按钮置灰+Lock图标,创建时拦截) ## 架构要点 - 证书签发流程: Vue → Java → Python API → acme.sh → 阿里云DNS API + Let's Encrypt - 邮件通知: Java @Scheduled → Mokee Gateway API → 邮件发送 - 系统域名 zgitm.com/www.zgitm.com 三层保护: 前端拦截 + Java校验 + Python API拒绝 - 手动创建域名保持内部CA签发(原有逻辑不变) ## 配置信息 - Mokee Gateway: https://gw.server.mokee.com (gw.base-url 可配置) - SystemCode: nginxServer - 阿里云 AccessKey: LTAI5t98jUxLUadZM1LkaSa8 / K2HyLLXizAgvOMOa0Mzc7ebs4gbAZs - acme.sh 路径: /root/.acme.sh/acme.sh - 证书目录: /etc/nginx/ssl/ ## 待处理 - [ ] 部署 Java 新版本到服务器并重启 - [ ] 前端构建部署 - [ ] 测试邮件通知(可临时改 cron 表达式触发) - [ ] 确认收件人邮箱(当前默认 admin@mokee.com)