Files
nginxserver/memory/session-20260612-2.md
2026-07-16 13:03:11 +08:00

84 lines
4.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
name: session-20260612-2
description: 2026-06-12 第2次会话 — 修复HTTPS转发规则创建后证书列表不显示
metadata:
type: session
date: 2026-06-12
sessionNumber: 2
startTime: 2026-06-12T12:00+08:00
---
# 2026-06-12 第2次会话
## 会话摘要
修复核心Bug创建 HTTPS 转发规则后,证书管理页面看不到对应证书。根因是 `ForwardingRuleService.addRule()` 只写 `forwarding_rules` 表没写 `certificates` 表,且 Python API 证书列表接口只扫描 `*.zgitm.com.pem` 文件。
## 关键操作
### 1. CertificateService 新增 syncCertificateRecord() + invalidateCache()
- **做了什么**:
- 新增 `syncCertificateRecord(domain, certPath, keyPath)` 方法upsert 证书记录
- 新增 `public void invalidateCache()` 暴露缓存失效
- **原因**: 创建/更新转发规则时需要同步写入 certificates 表
- **结果**: ForwardingRuleService 可调用此方法写入证书记录并立即失效缓存
- **文件**: `CertificateService.java`
### 2. ForwardingRuleService 注入 CertificateService
- **做了什么**:
- 注入 `CertificateService`(新增 `@Autowired`
- `addRule()`: HTTPS 协议时调用 `certificateService.syncCertificateRecord()`
- `updateRule()`: 同上
- **原因**: 修复创建/修改 HTTPS 规则时证书不写入 certificates 表的 Bug
- **结果**: 创建 HTTPS 规则后,证书管理页面立即显示对应证书
- **文件**: `ForwardingRuleService.java`
### 3. Python API 扩展证书扫描范围
- **做了什么**:
- `/api/nginx/certs`: 从只扫描 `*.zgitm.com.pem` 改为扫描全部 `*.pem` 文件
- `/api/nginx/certs/<domain>`: 移除 `is_zgitm_domain()` 限制,支持查询任意域名证书
- 排除 CA 根证书文件ca.pem, ca.crt
- **原因**: 内部 CA 签发的非 zgitm 域名证书无法通过同步机制发现
- **文件**: `app.py`
## 数据流(修复后)
```
创建 HTTPS 规则 → addRule()
├── Python API 签发证书 ✅
├── forwarding_rules 表 ✅
└── certificates 表 ✅ 新增syncCertificateRecord + invalidateCache
证书管理页面 → listCertificates()
└── 缓存已失效 → 直接查 DB → 立即显示 ✅
```
## 邮件通知架构确认
邮件通知和定时器已在 Java 后端实现:
- `CertNotifyScheduler.java`: @Scheduled(cron="0 0 10 * * ?") 每天10点
- 通过网关 API (`gw.server.zgitm.com`) 发送 HTML 邮件
- 只通知 letsencrypt 类型证书(含 notify 配置)
### 4. JPA → MyBatis-Plus 迁移
- **做了什么**: 全栈替换 Java 持久层框架23 个文件改动
- **原因**: 用户要求使用 MyBatis-Plus 替代 JPA
- **结果**: mvn clean compile BUILD SUCCESS零错误
- **文件**: pom.xml, application.yml, 3 Entity, 3 Mapper(新), 1 MetaObjectHandler(新), 3 Service, 1 Controller, 删除 3 Repository
### 6. Vue 前端移动端深度适配
- **做了什么**: 3 个页面表格→卡片视图,新增 useMobile composableMainLayout 复用 + 侧滑关闭App.vue 全局移动样式
- **原因**: 6-7列表格在手机上严重挤压需卡片化显示
- **结果**: BUILD SUCCESS移动端 Table→Card桌面端不变
- **文件**:
- 新增 `src/composables/useMobile.js`
- 修改 3 个 views (NginxForwarding/CertManagement/DnsManagement) — +卡片模板 + 卡片样式
- 修改 MainLayout.vue — 复用 useMobile + 侧滑关闭
- 修改 App.vue — 全局移动端增强(安全区域、字号、触摸优化)
### 7. gzip 修复 + proxy_buffering 优化
- **问题1**: nginx.conf 缺少 `gzip_types`,只压缩 text/htmlJS/CSS 完全不压缩
- **修复**: 添加 `gzip_types` 14 种 MIME 类型nginx -t 通过后 reload`Content-Encoding: gzip` 生效
- **问题2**: `web.gw.zgitm.com` 代理访问 40s vs 直连 3-10s
- **根因**: proxy_buffering 默认开启nginx 等后端全部返回后才发给客户端,延迟叠加
- **修复**: 全部 17 个 conf.d 配置加 `proxy_buffering off`Python API 模板同步更新4处确保未来新增规则也生效