fix: 适配新服务器蓝绿部署 — nginx 原生/PostgreSQL Docker 容器名/部署脚本
Some checks failed
Deploy Backend / deploy (push) Has been cancelled

This commit is contained in:
2026-07-13 18:30:33 +08:00
parent 38ee5ccbc6
commit ba00fcb1c6
6 changed files with 101 additions and 78 deletions

View File

@@ -1,4 +1,9 @@
# 蓝绿部署计划
# 蓝绿部署(新服务器)
> **服务器**47.109.203.92 (Aliyun, Debian 13)
> **nginx**:原生 nginx非 Docker/OpenResty
> **PostgreSQL**Docker 容器 `postgres:17.6-alpine`
> **部署用户**`deploy`(有 sudo 权限)
## 域名与环境映射
@@ -28,7 +33,7 @@ xmclassmate.top 生产 :4433 / :4434 milkydata
```
dev.xmclassmate.top
OpenResty → :8080单实例
nginx → :8080单实例
milkydata_dev
```
@@ -48,9 +53,9 @@ dev.xmclassmate.top
```
xmclassmate.top
OpenResty proxy
nginx proxy直接路由
/ \
蓝色 :4433 绿色 :4434
蓝色 :4433 绿色 :4434
(active) (idle)
\ /
milkydata共享
@@ -70,16 +75,18 @@ xmclassmate.top
两个 service 的 `DATABASE_URL` 都指向 `milkydata`,仅端口不同。
**OpenResty proxy 配置:**
**nginx proxy 配置:**
```
# /www/sites/xmclassmate.top/proxy/root.conf
location ^~ / {
proxy_pass http://127.0.0.1:4433; # deploy.sh 切换此端口
proxy_pass https://127.0.0.1:4433; # deploy.sh 切换此端口
}
```
切换时 `sed` 替换端口,`nginx -s reload`
> 生产环境使用 HTTPS proxy`proxy_pass https://...`),因为后端自身处理 TLS
切换时 `sed` 替换端口,`sudo nginx -s reload`
### 部署流程
@@ -110,9 +117,11 @@ location ^~ / {
### 切换脚本
```bash
./scripts/switch-env.sh --env prod --switch green
./scripts/switch-env.sh --switch green
# 或切回蓝色
./scripts/switch-env.sh --env prod --switch blue
./scripts/switch-env.sh --switch blue
# 查看当前状态
./scripts/switch-env.sh --status
```
### 回滚
@@ -203,11 +212,11 @@ cargo build --release && rsync ... systemctl restart ← ❌
| # | 步骤 | 说明 | 状态 |
|---|------|------|------|
| 1 | 数据迁移 | 已完成 | ✅ |
| 2 | 准备生产 service 文件(填入实际密钥) | 完成 | |
| 3 | 部署新代码到 `:4433` | 完成 | |
| 2 | 准备生产 service 文件 | 完成 | |
| 3 | 部署新代码到 `:4433``:4434` | 完成 | |
| 4 | `env.ts``CURRENT_ENV = 'production'` | 已完成 | ✅ |
| 5 | 微信开发者工具上传小程序 | 完成 | |
| 6 | 1Panel 确认 `proxy_pass` 指向 `:4433` | 已完成 | ✅ |
| 5 | 微信开发者工具上传小程序 | 完成 | |
| 6 | 确认 nginx `proxy_pass` 指向 :4433 | 已完成 | ✅ |
## 实施状态
@@ -215,11 +224,11 @@ cargo build --release && rsync ... systemctl restart ← ❌
| 组件 | 状态 |
|------|------|
| Blue service (:4433) | ✅ 运行中,ConfigID `71ba8887` |
| Green service (:4434) | ✅ 运行中,活动中 |
| `deploy.sh --target blue\|green` | ✅ 已支持 |
| `switch-env.sh --switch blue\|green` | ✅ 自动切换 |
| OpenResty proxy | ✅ 指向活动中环境 |
| Blue service (:4433) | ✅ 运行中,当前活跃 |
| Green service (:4434) | ✅ 运行中,待命中 |
| `deploy.sh production --target blue/green` | ✅ 已支持 |
| `switch-env.sh --switch blue/green` | ✅ 自动切换 nginx proxy |
| nginx proxy | ✅ 指向活动中环境 |
### 下次部署流程