Compare commits

..
Author SHA1 Message Date
总工andmultica-agent c9e8e113d0 fix(deploy): 复核修正——补齐 /downloads/ APK 路由并加固切换脚本 (HEL-552)
- host-nginx/jxd.jinniu.ink.conf:线上 jxd-edge 实际配置里有 /downloads/ 路由
  (HEL-279 验收后现场热修,仓库未同步),新模板漏迁会导致已交付验收链接
  /downloads/jinxunda-android-test-1.0.9.apk 失效。补齐该路由,占位符
  __JXD_DOWNLOADS_DIR__ 由切换脚本替换;另加 proxy_cache off 防止宝塔
  http{} 级全局 proxy_cache 缓存 API/WebSocket 响应;http2 改用独立指令。
- docker-compose.edge-fallback.yaml:补 downloads 只读挂载,保证回滚后下载可用。
- deploy/public/nginx.conf:与线上运行配置逐字节对齐(已 diff 验证一致)。
- switch-to-host-nginx.sh:裸 pgrep -x nginx 会被宿主机上其他 nginx 容器
  (solsum 首页容器)误报,导致对已停止的宝塔 Nginx 执行 reload 必然失败
  且不触发回滚、80/443 无人监听。改为按 pidfile 判定系统 Nginx 本尊,
  start/reload 失败立即自动回滚。
- README.md:修正 APK 下载现状描述(原文称线上无下载路由,与实际不符)。

Co-authored-by: multica-agent <github@multica.ai>
2026-09-14 17:22:42 +08:00
354495ec78 feat(deploy): 系统 Nginx 统一入口取代 jxd-edge,消除公网 80/443 端口冲突 (HEL-551)
- 新增 deploy/public/host-nginx/jxd.jinniu.ink.conf:给系统/宝塔 Nginx 用的站点配置,
  1:1 迁移原 jxd-edge nginx.conf 的全部路由(/msg_gateway、/account/、/files/、
  /livekit/、REST API catch-all、ACME challenge、HTTPS、超时与上传大小限制),
  WebSocket 升级头改为自包含写法(不依赖全局 map 指令),可独立作为站点文件存在。
- docker-compose.public.yaml 删除占用 host 网络的 edge 服务;内部端口保持只绑
  127.0.0.1,语音媒体端口 17881/tcp、17882/udp 不变。
- 新增 docker-compose.edge-fallback.yaml:仅供应急回滚时恢复 jxd-edge 使用,
  不叠进日常启动命令。
- 新增 scripts/switch-to-host-nginx.sh:备份 -> 生成站点配置 -> nginx -t 语法检查
  -> 停旧 edge -> 启动/重载系统 Nginx -> 健康检查,任一步失败自动回滚。
- 新增 scripts/rollback-to-jxd-edge.sh:禁用系统 Nginx 站点文件、重新拉起
  jxd-edge,一键回到旧方案。
- 更新 scripts/rollback-public.sh 以同时清理 edge-fallback 场景下的 jxd-edge 容器。
- 更新 deploy/public/README.md:新增共享服务器铁律、统一入口切换步骤、证书续期
  说明,并核实 APK 下载当前不经过 jxd-edge(走工单附件分发)。

本卡不登录服务器、不改防火墙、不停容器、不启动系统 Nginx;仅完成代码/配置模板
与部署文档,切换由总工审核执行。

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: multica-agent <github@multica.ai>
2026-09-14 16:53:26 +08:00
24 changed files with 401 additions and 338 deletions
-1
View File
@@ -5,7 +5,6 @@
# 不匹配 pc-client/src/components 等源码子目录,保证其可入库
/components/
.selftest/
pc-client/dist-portal/
data/
**/agconnect-services.json
+1 -1
View File
@@ -1,6 +1,6 @@
FROM node:20-alpine
WORKDIR /app
COPY server.js portal-sso.js admin.html ./
COPY server.js admin.html ./
ENV PORT=10010 DATA_FILE=/app/data/employees.json
EXPOSE 10010
CMD ["node", "server.js"]
-142
View File
@@ -1,142 +0,0 @@
'use strict';
const crypto = require('crypto');
const fs = require('fs');
const path = require('path');
const digest = s => crypto.createHash('sha256').update(s).digest('hex');
const hex = s => typeof s === 'string' && /^[a-f0-9]{64}$/.test(s);
// Browser-bound portal tickets. OpenIM user IDs are permanent empids, not mutable staff numbers.
module.exports = function createPortalBridge(deps, env = process.env) {
const enabled = env.PORTAL_SSO_ENABLED === '1';
if (!enabled) return { handle: async () => false };
const portal = new URL(env.PORTAL_PUBLIC_URL);
const internal = new URL(env.PORTAL_INTERNAL_URL);
const secret = env.PORTAL_SSO_SECRET || '';
if (!['http:', 'https:'].includes(internal.protocol) || portal.protocol !== 'https:' || secret.length < 32)
throw new Error('Invalid portal configuration');
const file = path.join(path.dirname(env.DATA_FILE), 'portal-sessions.json');
let sessions = fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, 'utf8')) : {};
const cookieFlags = '; HttpOnly; Secure; SameSite=Lax; Path=/';
const cookieName = '__Host-jxd_portal_sid';
const save = () => {
fs.mkdirSync(path.dirname(file), { recursive: true });
fs.writeFileSync(file + '.tmp', JSON.stringify(sessions), { mode: 0o600 });
fs.renameSync(file + '.tmp', file);
};
const cookies = req => Object.fromEntries(String(req.headers.cookie || '').split(';').map(p => {
const n = p.indexOf('='); return [p.slice(0, n).trim(), p.slice(n + 1)];
}));
async function call(operation, payload) {
const response = await fetch(new URL('/api/sso/apps/jinxunda/' + operation, internal), {
method: 'POST', redirect: 'error', signal: AbortSignal.timeout(5000),
headers: { Authorization: 'Bearer ' + secret, 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
});
if (!response.ok) throw new Error('Portal unavailable');
return response.json();
}
function reply(res, status, value) {
res.writeHead(status, { 'Content-Type': 'application/json; charset=utf-8',
'Cache-Control': 'no-store', 'Referrer-Policy': 'no-referrer' });
res.end(JSON.stringify(value));
}
function redirect(res, location, cookie) {
res.writeHead(303, { Location: location, 'Set-Cookie': cookie,
'Cache-Control': 'no-store', 'Referrer-Policy': 'no-referrer' }); res.end();
}
async function valid(row) {
const r = await call('introspect', { session_handle: row.handle });
return r.active && r.identity?.empid === row.empid && r.identity?.local_uid === row.localUid;
}
async function revoke(key) {
const row = sessions[key];
if (!row) return;
row.revoked = true;
save();
// Persist revocation before kicking; failed kicks are retried by the sweep.
const token = await deps.getAdminToken();
const result = await deps.imApi('/auth/force_logout', { platformID: 5, userID: row.imUid }, token);
if (result.errCode !== 0) throw new Error('IM revocation pending');
delete sessions[key]; save();
}
let sweeping = false;
const timer = setInterval(async () => {
if (sweeping) return;
sweeping = true;
try {
for (const [key, row] of Object.entries(sessions)) {
let active = false;
try { active = !row.revoked && await valid(row); } catch { /* fail closed */ }
if (!active) { try { await revoke(key); } catch { /* retry next sweep */ } }
}
} finally { sweeping = false; }
}, 10000);
timer.unref();
return {
close: () => clearInterval(timer),
async handle(req, res) {
const url = new URL(req.url, 'http://localhost');
const route = url.pathname;
if (route === '/portal-sso') {
if (req.method !== 'GET') { reply(res, 405, { message: 'Method not allowed' }); return true; }
try {
const ticket = url.searchParams.get('ticket');
if (!ticket) {
const verifier = crypto.randomBytes(32).toString('hex');
const theme = url.searchParams.get('theme') === 'night' ? 'night' : 'day';
const value = [verifier, Date.now(), theme].join('.');
redirect(res, new URL('/api/sso/apps/jinxunda/authorize?challenge=' + digest(verifier), portal).href,
'__Host-jxd_proof=' + value + cookieFlags + '; Max-Age=120');
return true;
}
const [verifier, timestamp, theme] = (cookies(req)['__Host-jxd_proof'] || '').split('.');
if (!hex(ticket) || !hex(verifier) || !Number.isFinite(Number(timestamp))
|| Date.now() - Number(timestamp) > 120000 || Number(timestamp) > Date.now())
throw new Error('Invalid browser proof');
const result = await call('exchange', { ticket, verifier });
const who = result.identity;
if (!hex(result.session_handle) || !/^[a-f0-9-]{36}$/.test(who?.empid || '')
|| !Number.isSafeInteger(who?.local_uid) || who.local_uid < 1)
throw new Error('Invalid identity');
// OpenIM rejects UUID hyphens. Preserve empid and derive its lossless 32-hex representation.
const imUid = who.empid.replace(/-/g, '');
if (!/^[a-f0-9]{32}$/.test(imUid)) throw new Error('Invalid permanent identity');
if (!await deps.ensureImUser(imUid, who.display_name)) throw new Error('IM unavailable');
const token = await deps.getImUserToken(imUid, 5);
const sid = crypto.randomBytes(32).toString('hex');
sessions[digest(sid)] = { handle: result.session_handle, empid: who.empid, imUid,
localUid: who.local_uid, staffNo: who.username, name: who.display_name,
token: token.token, theme: theme === 'night' ? 'night' : 'day' };
save();
redirect(res, '/#/chat', [cookieName + '=' + sid + cookieFlags + '; Max-Age=28800',
'__Host-jxd_proof=' + cookieFlags + '; Max-Age=0']);
} catch (error) {
console.error('Portal SSO failed:', String(error.message).replace(/[a-f0-9]{32,}/gi, '[redacted]').slice(0, 180));
reply(res, 401, { message: '统一登录未完成,请返回门户重新进入。', portal: portal.origin });
}
return true;
}
if (route === '/api/portal/session') {
if (req.method !== 'GET') { reply(res, 405, {}); return true; }
const sid = cookies(req)[cookieName];
const key = hex(sid) ? digest(sid) : '';
const row = sessions[key];
try {
if (!row || row.revoked || !await valid(row)) throw new Error('Invalid session');
reply(res, 200, { userID: row.imUid, imToken: row.token, chatToken: row.token,
displayName: row.name, staffNo: row.staffNo, theme: row.theme, portal: portal.origin });
} catch {
if (row) { try { await revoke(key); } catch { /* retry */ }
}
reply(res, 401, { message: '请从统一门户进入金讯达', portal: portal.origin });
}
return true;
}
// The existing app must not retain a parallel password/admin entry.
if (route === '/api/login' || route === '/' || route === '/admin' || route.startsWith('/api/admin/')) {
reply(res, 403, { message: '账号及登录统一由门户管理', portal: portal.origin }); return true;
}
return false;
},
};
};
-2
View File
@@ -357,10 +357,8 @@ const routes = {
},
};
const portalBridge = require('./portal-sso')({ getAdminToken, imApi, ensureImUser, getImUserToken });
const server = http.createServer(async (req, res) => {
try {
if (await portalBridge.handle(req, res)) return;
const url = new URL(req.url, 'http://localhost');
req.urlObj = url;
if (req.method === 'OPTIONS') return send(res, 204, {});
-65
View File
@@ -1,65 +0,0 @@
'use strict';
const test = require('node:test');
const assert = require('node:assert/strict');
const http = require('http');
const fs = require('fs');
const os = require('os');
const path = require('path');
const createBridge = require('./portal-sso');
test('portal proof, exchange, active session, revocation, and legacy login closure', async () => {
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'jinniu-sso-test-'));
let active = true, exchanges = 0, kicks = 0;
const identity = { empid: 'fefafefa-1234-1234-1234-123456789abc', local_uid: 1, username: '019999', display_name: '管理员' };
const portal = http.createServer(async (req, res) => {
assert.equal(req.headers.authorization, 'Bearer ' + 's'.repeat(32));
res.setHeader('Content-Type', 'application/json');
if (req.url.endsWith('/exchange')) {
exchanges++;
res.end(JSON.stringify({ identity, session_handle: 'c'.repeat(64) }));
} else res.end(JSON.stringify({active, identity}));
});
await new Promise(r => portal.listen(0,'127.0.0.1',r));
const bridge = createBridge({
ensureImUser: async (uid) => { assert.equal(uid, identity.empid.replace(/-/g,'')); return true; },
getImUserToken: async (uid, pid) => { assert.equal(pid, 5); return {token:'private-im-token'}; },
getAdminToken: async () => 'private-admin-token',
imApi: async (route, body) => { assert.equal(body.userID, identity.empid.replace(/-/g,'')); kicks++; return {errCode:0}; },
}, {PORTAL_SSO_ENABLED:'1', PORTAL_SSO_SECRET:'s'.repeat(32), PORTAL_PUBLIC_URL:'https://bg.example.test',
PORTAL_INTERNAL_URL:'http://127.0.0.1:'+portal.address().port, DATA_FILE:path.join(temp,'employees.json')});
const server = http.createServer(async (req,res) => { if (!await bridge.handle(req,res)) { res.writeHead(404);res.end(); } });
await new Promise(r => server.listen(0,'127.0.0.1',r));
const base = 'http://127.0.0.1:'+server.address().port;
try {
assert.equal((await fetch(base+'/api/login',{method:'POST'})).status,403);
assert.equal((await fetch(base+'/api/admin/employees')).status,403);
assert.equal((await fetch(base+'/api/portal/session')).status,401);
assert.equal((await fetch(base+'/portal-sso?ticket='+'a'.repeat(64))).status,401);
assert.equal(exchanges,0);
const start = await fetch(base+'/portal-sso?theme=night',{redirect:'manual'});
assert.equal(start.status,303);
assert.match(start.headers.get('location'),/^https:\/\/bg\.example\.test\/api\/sso\/apps\/jinxunda\/authorize\?challenge=[a-f0-9]{64}$/);
const proof = start.headers.get('set-cookie').split(';')[0];
const finish = await fetch(base+'/portal-sso?ticket='+'a'.repeat(64),{redirect:'manual',headers:{cookie:proof}});
assert.equal(finish.status,303);
const cookie = finish.headers.getSetCookie()[0].split(';')[0];
assert.match(finish.headers.getSetCookie()[0],/HttpOnly; Secure; SameSite=Lax/);
let r = await fetch(base+'/api/portal/session',{headers:{cookie}});
assert.equal(r.headers.get('cache-control'),'no-store');
const profile=await r.json();
assert.equal(profile.userID,identity.empid.replace(/-/g,''));
assert.equal(profile.staffNo,'019999');
assert.equal(profile.theme,'night');
active=false;
r = await fetch(base+'/api/portal/session',{headers:{cookie}});
assert.equal(r.status,401);
assert.equal(kicks,1);
assert.deepEqual(JSON.parse(fs.readFileSync(path.join(temp,'portal-sessions.json'))),{});
} finally {
bridge.close();
await new Promise(r=>server.close(r));
await new Promise(r=>portal.close(r));
assert.ok(path.resolve(temp).startsWith(path.resolve(os.tmpdir())+path.sep));
fs.rmSync(temp,{recursive:true});
}
});
+49 -5
View File
@@ -4,6 +4,39 @@
目标机:已解析到 `jxd.jinniu.ink` 的香港测试服务器。数据目录仍是仓库下的 `components/` 与 `data/`,回滚不删数据。
## 共享服务器铁律(HEL-551)
这台服务器不止跑金讯达一个项目(还要给 `solsum.cn` 等域名提供服务),所以:
- 公网 `80/443` 只能由**一套**统一入口持有——现在是系统/宝塔 Nginx,不是某个项目自己的容器。
- 新增域名/项目,只在系统 Nginx 里新增一个站点配置文件,不要另起一个监听 80/443 的边缘容器。
- 任何业务容器都不允许用 `network_mode: host` 或直接绑 `0.0.0.0:80` / `0.0.0.0:443` 抢占入口端口;容器只把业务端口绑到 `127.0.0.1`,由系统 Nginx 反代。
- `jxd-edge`(HEL-279 时代的方案)已经因为这条铁律下线,定义保留在 `docker-compose.edge-fallback.yaml` 仅供应急回滚,不要在日常启动里叠加它。
## 统一入口:系统 Nginx 取代 jxd-edge
自 HEL-551 起,`jxd.jinniu.ink` 的 80/443 由服务器上的系统/宝塔 Nginx 直接持有并反代,不再用独占 host 网络的 `jxd-edge` 容器:
- 站点配置模板:`deploy/public/host-nginx/jxd.jinniu.ink.conf`(1:1 迁移了原 `nginx.conf` 里的全部路由:`/msg_gateway`、`/account/`、`/files/`、`/livekit/`、REST API catch-all、ACME challenge、HTTPS、超时与上传大小限制)。
- `docker-compose.public.yaml` 里的 `edge` 服务已删除;金讯达各容器的内部端口本来就只绑 `127.0.0.1`,不受影响。
- 切换脚本:`scripts/switch-to-host-nginx.sh`(备份 → 语法检查 → 停旧 edge → 启动/重载系统 Nginx → 健康检查,任一步失败自动回滚)。
- 回滚脚本:`scripts/rollback-to-jxd-edge.sh`(禁用系统 Nginx 上的 jxd 站点文件,重新拉起 `jxd-edge`,配合 `deploy/public/docker-compose.edge-fallback.yaml`)。
切换步骤(总工在服务器上执行,按需通过环境变量覆盖 `HOST_NGINX_VHOST_DIR` / `HOST_NGINX_BIN` / `HOST_NGINX_INIT` 适配实际路径):
```bash
cd /path/to/tongxunruanjian
./scripts/switch-to-host-nginx.sh
```
一键回滚(切换失败会自动触发,也可以随时手动执行):
```bash
./scripts/rollback-to-jxd-edge.sh
```
**APK 下载现状核实(HEL-552 复核修正)**:仓库里的旧 `nginx.conf` 曾缺少 APK 下载路由,但线上 `jxd-edge` 实际运行配置里**有** `/downloads/` 路由,并挂载了 `deploy/public/downloads`(HEL-279 验收后现场热修加入,仓库未同步)。已交付验收地址为 `https://jxd.jinniu.ink/downloads/jinxunda-android-test-1.0.9.apk`。现已把 `/downloads/` 路由补进系统 Nginx 站点模板(占位符 `__JXD_DOWNLOADS_DIR__`)、回滚用 `docker-compose.edge-fallback.yaml` 的挂载、以及本仓库 `nginx.conf` 本身,三处与线上一致,切换与回滚后该链接均不失效。
## 对外暴露与对内绑定
| 入口 | 协议 | 后端 | 说明 |
@@ -19,11 +52,15 @@
## 证书
首次签发(历史步骤,测试机已经跑过一次,证书已经存在,仅在证书丢失/重建时才需要重跑):
1. 先把 `deploy/public/nginx.bootstrap.conf` 挂到 edge(只听 80)。
2. `certbot certonly --webroot -w deploy/public/acme -d jxd.jinniu.ink`
3. 确认 `/etc/letsencrypt/live/jxd.jinniu.ink/` 有 `fullchain.pem` 与 `privkey.pem`。
4. 改回 `nginx.conf` 后重载 edge。
**HEL-551 后的续期**:系统 Nginx 站点配置(`deploy/public/host-nginx/jxd.jinniu.ink.conf`)里的 ACME challenge `root` 指向的还是同一个 `deploy/public/acme` 目录,`switch-to-host-nginx.sh` 会自动替换成绝对路径。只要 certbot 续期时仍用这个目录做 webroot,就不需要重新申请证书,也不用再依赖 `jxd-edge` 来响应 `.well-known/acme-challenge`。
私钥不得复制进 Git。
## 极光 Master Secret
@@ -44,17 +81,24 @@ cp .env.example .env # 若还没有
# 按 deploy/public/.env.public.example 写入 SERVER_IP、MINIO_EXTERNAL_ADDRESS、JPUSH_*(不含 Master Secret)
source ./scripts/load-jpush-secret.sh
./scripts/deploy-public.sh
./scripts/switch-to-host-nginx.sh # HEL-551 起:让系统 Nginx 接管 80/443
```
`SERVER_IP` 填本机公网 IP(LiveKit 媒体候选),不要写进手机/电脑客户端代码。
`deploy-public.sh` 本身只拉起金讯达容器(内部端口只绑 `127.0.0.1`),不再包含监听 80/443 的边缘容器;`switch-to-host-nginx.sh` 是让系统 Nginx 对外接管入口这一步,缺了它 `jxd.jinniu.ink` 在公网上访问不到。
## 回滚
```bash
./scripts/rollback-public.sh
```
效果:停掉 nginx edge,按原来的 `docker-compose.yaml` 拉起;`components/` 与 `data/account` 不动。
- 只想让 jxd-edge 重新接管 80/443(系统 Nginx 切换出问题时的应急手段):
```bash
./scripts/rollback-to-jxd-edge.sh
```
- 想整体退回内网部署(不对外暴露):
```bash
./scripts/rollback-public.sh
```
效果:清理 jxd-edge(如果在跑),按原来的 `docker-compose.yaml` 拉起;`components/` 与 `data/account` 不动。系统 Nginx 上的 jxd 站点文件不受影响,需要的话手工禁用或用 `rollback-to-jxd-edge.sh` 里的第一步。
## 客户端地址(已写进代码默认值)
@@ -0,0 +1,36 @@
# 应急回滚专用 overlay(HEL-551)——不要在日常启动里叠加这个文件。
#
# 这里保留的是 HEL-279 时代 jxd-edge 的原始定义:用 host 网络独占 80/443。
# 只有在系统/宝塔 Nginx 切换失败、需要立刻恢复公网访问时才用它,配合
# scripts/rollback-to-jxd-edge.sh 一起执行:
#
# docker compose \
# -f docker-compose.yaml \
# -f deploy/public/docker-compose.public.yaml \
# -f deploy/public/docker-compose.edge-fallback.yaml \
# up -d edge
#
# 恢复系统 Nginx 统一入口后,记得停掉并移除这个容器:
# docker compose -f docker-compose.yaml -f deploy/public/docker-compose.public.yaml \
# -f deploy/public/docker-compose.edge-fallback.yaml stop edge
# docker compose -f docker-compose.yaml -f deploy/public/docker-compose.public.yaml \
# -f deploy/public/docker-compose.edge-fallback.yaml rm -f edge
#
# 不得同时有 jxd-edge(host 网络)和系统 Nginx 一起监听 80/443——两者互斥。
services:
edge:
image: nginx:1.27-alpine
container_name: jxd-edge
restart: always
network_mode: host
volumes:
- ./deploy/public/nginx.conf:/etc/nginx/nginx.conf:ro
- ./deploy/public/acme:/var/www/acme:ro
- ./deploy/public/downloads:/var/www/downloads:ro
- /etc/letsencrypt:/etc/letsencrypt:ro
depends_on:
- openim-server
- account-server
- minio
- livekit
+8 -15
View File
@@ -7,6 +7,14 @@
# 原则:内部端口只绑 127.0.0.1;对外只开 80/443 + LiveKit 媒体 17881/tcp、17882/udp。
# ports 使用 !override,避免与基础 compose 的 0.0.0.0 绑定叠加。
# 回滚:去掉本 overlay,改回 docker compose -f docker-compose.yaml up -d,数据目录 components/ 与 data/ 不动。
#
# HEL-551:80/443 已交给系统/宝塔 Nginx 统一持有,本 overlay 不再包含独占
# host 网络的 jxd-edge 容器(这是共享服务器上和其他域名冲突的根因)。
# 上面几个服务的内部端口本来就只绑 127.0.0.1,系统 Nginx 直接反代这些端口即可,
# 见 deploy/public/host-nginx/jxd.jinniu.ink.conf。
# 应急回滚(系统 Nginx 切换失败时)才用得到旧的 edge 容器定义,见
# deploy/public/docker-compose.edge-fallback.yaml 与 scripts/rollback-to-jxd-edge.sh,
# 不要把 edge-fallback 叠进日常启动命令。
services:
openim-server:
@@ -42,18 +50,3 @@ services:
account-server:
ports: !override
- "127.0.0.1:${ACCOUNT_PORT:-10010}:10010"
edge:
image: nginx:1.27-alpine
container_name: jxd-edge
restart: always
network_mode: host
volumes:
- ./deploy/public/nginx.conf:/etc/nginx/nginx.conf:ro
- ./deploy/public/acme:/var/www/acme:ro
- /etc/letsencrypt:/etc/letsencrypt:ro
depends_on:
- openim-server
- account-server
- minio
- livekit
@@ -0,0 +1,139 @@
# jxd.jinniu.ink 站点配置 —— 给系统/宝塔 Nginx 用(HEL-551)。
#
# 用途:把这个文件放进系统 Nginx 的站点目录(宝塔一般是
# /www/server/panel/vhost/nginx/,原生 Nginx 一般是 /etc/nginx/conf.d/),
# 让系统 Nginx 作为 80/443 的唯一持有者,替换掉原来独占 host 网络的
# jxd-edge 容器。不要整份替换系统 Nginx 的 nginx.conf,这里只是新增一个
# 站点文件,和 solsum.cn 等其他站点的配置文件平级共存。
#
# 使用前必须替换的占位符:
# __JXD_ACME_WEBROOT__ -> 本机 tongxunruanjian 仓库的绝对路径 + /deploy/public/acme
# (例如 /opt/tongxunruanjian/deploy/public/acme)。
# 这必须是 certbot 当初签发 jxd.jinniu.ink 证书时用的同一个
# webroot 目录,这样证书续期不用重新申请。
# __JXD_DOWNLOADS_DIR__ -> 本机 tongxunruanjian 仓库的绝对路径 + /deploy/public/downloads
# (例如 /opt/tongxunruanjian/deploy/public/downloads)。
# 安卓测试安装包目录,对应原 jxd-edge 的 /downloads/ 路由,
# 已交付的验收链接 /downloads/jinxunda-android-test-1.0.9.apk 依赖它。
# scripts/switch-to-host-nginx.sh 会自动完成这两个替换,见该脚本与
# ../README.md「切换到系统 Nginx」一节;手工部署时也可以自己 sed 替换。
#
# 依赖的后端端口(均只监听 127.0.0.1,由 docker-compose.public.yaml 保证):
# OpenIM 消息网关 127.0.0.1:10001
# OpenIM API 127.0.0.1:10002
# 账号服务 127.0.0.1:10010
# MinIO(对象存储) 127.0.0.1:10005
# LiveKit 信令 127.0.0.1:17880
# 如果 .env 里改过 *_PORT,要同步改这里的端口号。
#
# 说明:/msg_gateway 与 /livekit/ 是专用的 WebSocket 升级端点,这里直接把
# Connection 头写死成 "upgrade",不依赖全局 map $http_upgrade $connection_upgrade
# 指令 —— 这样这个站点文件可以独立存在,不需要改系统 Nginx 主配置的 http{} 块。
server {
listen 80;
listen [::]:80;
server_name jxd.jinniu.ink;
# ACME HTTP-01 挑战,续期证书用。
location /.well-known/acme-challenge/ {
root __JXD_ACME_WEBROOT__;
}
location / {
return 301 https://$host$request_uri;
}
}
server {
# http2 指令写法需要 nginx >= 1.25.1(目标服务器宝塔 nginx 为 1.28.0)。
# 不要写回 `listen 443 ssl http2`,1.25.1+ 上会报弃用告警。
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
server_name jxd.jinniu.ink;
ssl_certificate /etc/letsencrypt/live/jxd.jinniu.ink/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/jxd.jinniu.ink/privkey.pem;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:10m;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;
client_max_body_size 100m;
# 宝塔主配置的 http{} 里有全局 proxy_cache(见 /www/server/nginx/conf/proxy.conf 的
# proxy_cache cache_one),API/WebSocket 代理绝不能吃缓存——显式关掉,
# 保持与原 jxd-edge(无任何缓存)行为一致。
proxy_cache off;
# OpenIM 消息长连接(WebSocket)
location /msg_gateway {
proxy_pass http://127.0.0.1:10001/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
}
# 公司账号服务(登录、管理页、rtc_token)
location /account/ {
proxy_pass http://127.0.0.1:10010/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# MinIO 对象(MINIO_EXTERNAL_ADDRESS=https://jxd.jinniu.ink/files)
location /files/ {
proxy_pass http://127.0.0.1:10005/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_request_buffering off;
}
# LiveKit 信令(客户端 wss://jxd.jinniu.ink/livekit/ ...)
location /livekit/ {
proxy_pass http://127.0.0.1:17880/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
}
# 安卓测试安装包下载(1:1 迁移自线上 jxd-edge 的 /downloads/ 路由,HEL-552 复核补齐)。
# 已交付验收地址:https://jxd.jinniu.ink/downloads/jinxunda-android-test-1.0.9.apk
location /downloads/ {
alias __JXD_DOWNLOADS_DIR__/;
types {
application/vnd.android.package-archive apk;
}
default_type application/octet-stream;
add_header Content-Disposition "attachment";
limit_except GET HEAD {
deny all;
}
}
# OpenIM REST API(catch-all,须放最后)
location / {
proxy_pass http://127.0.0.1:10002;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
+13
View File
@@ -108,6 +108,19 @@ http {
proxy_send_timeout 3600s;
}
# 安卓测试安装包(只读下载目录)
location /downloads/ {
alias /var/www/downloads/;
types {
application/vnd.android.package-archive apk;
}
default_type application/octet-stream;
add_header Content-Disposition "attachment";
limit_except GET HEAD {
deny all;
}
}
# OpenIM REST API(catch-all,须放最后)
location / {
proxy_pass http://openim_api;
-24
View File
@@ -1,24 +0,0 @@
# 金讯达统一门户网页试运行
网页地址 https://jxd.jinniu.ink,唯一身份入口 https://bg.jinniu.ink。
account-service 设置 PORTAL_SSO_ENABLED=1、PORTAL_PUBLIC_URL、PORTAL_INTERNAL_URL 和独立不少于32字符的 PORTAL_SSO_SECRET。该密钥必须与门户 JINXUNDA_SSO_SECRET 一致。现有 OpenIM 管理服务密钥仍通过私有环境文件提供。
`/portal-sso` 使用浏览器 verifier 绑定的短期一次性票据。身份使用永久 empid,OpenIM UID 为去掉 UUID 连字符的32位十六进制表示。不能用工号改名重新创建聊天身份。
`/api/portal/session` 同源且禁止缓存;每次验证门户会话。后台每10秒撤销失效用户平台5会话,失败会重试。会话文件仅服务端可读,原口令登录和管理API在门户模式禁用。
构建 pc-client 网页版本时配置:
```
VITE_PORTAL_MODE=1
VITE_PORTAL_URL=https://bg.jinniu.ink
VITE_API_URL=https://jxd.jinniu.ink
VITE_WS_URL=wss://jxd.jinniu.ink/msg_gateway
VITE_ACCOUNT_URL=https://jxd.jinniu.ink/account
VITE_LIVEKIT_URL=wss://jxd.jinniu.ink/livekit/
```
执行 `npx vite build --config vite.portal.config.ts`,输出 dist-portal。Nginx 将根路径/资源指向该目录,SSO及会话接口代理账号服务;原OpenIM、对象存储、LiveKit路由保留。
验证:`node --test test-portal-sso.js test-admin-page.js`(在account-service目录);真实HTTPS兑换OpenIM凭证、浏览器进入聊天、返回门户、退出撤销已验收。
仅保留一个正式管理员,因此双人消息、音视频、附件尚未完成真实员工验收。原生Windows/Android客户端仍为历史登录机制,需要另行适配门户登录;不能视为本次网页交付已覆盖。
+2 -3
View File
@@ -25,7 +25,6 @@ import { OverlayVisibleHandle } from "../../hooks/useOverlayVisible";
import About from "./About";
import styles from "./left-nav-bar.module.scss";
import PersonalSettings from "./PersonalSettings";
import { portalMode } from '@/portal';
const AppIcon = () => (
<div className="flex h-9 w-9 items-center justify-center rounded-lg bg-[var(--primary)]">
@@ -282,7 +281,7 @@ const LeftNavBar = memo(() => {
))}
</div>
{!portalMode && <Popover
<Popover
content={ProfileContent}
trigger="click"
placement="rightBottom"
@@ -298,7 +297,7 @@ const LeftNavBar = memo(() => {
src={selfInfo.faceURL}
text={selfInfo.nickname}
/>
</Popover>}
</Popover>
<PersonalSettings ref={personalSettingsRef} />
<About ref={aboutRef} />
</div>
+1 -3
View File
@@ -9,7 +9,6 @@ import { useUserStore } from "@/store";
import GlobalModals from "./GlobalModals";
import LeftNavBar from "./LeftNavBar";
import { useGlobalEvent } from "./useGlobalEvents";
import { portalMode, portalHome } from '@/portal';
export const MainContentLayout = () => {
useGlobalEvent();
@@ -36,8 +35,7 @@ export const MainContentLayout = () => {
return (
<Spin className="!max-h-none" spinning={showLockLoading} tip={loadingTip}>
{portalMode && <header className="portal-header"><strong>金讯达</strong><span>金牛集团 · 内部通讯</span><a href={portalHome + '?theme=' + document.documentElement.dataset.theme}>返回统一门户</a></header>}
<Layout className="relative h-full flex-row" style={portalMode ? {height: 'calc(100% - 56px)'} : undefined}>
<Layout className="relative h-full flex-row">
<LeftNavBar />
<Outlet />
{/* 悬浮窗口控制条:无边框窗口的拖动区 + 最小化/关闭 */}
+1 -19
View File
@@ -7,8 +7,6 @@ import ReactDOM from "react-dom/client";
import App from "./App";
import { isSaveLog } from "./config";
import { initializePortal, portalHome, portalMode } from './portal';
import './portal.scss';
if (window.electronAPI && isSaveLog) {
const sdkLogger = log.scope("openim-sdk-core");
@@ -18,22 +16,6 @@ if (window.electronAPI && isSaveLog) {
console.error = rendererLogger.error.bind(rendererLogger);
}
initializePortal().then(ready => {
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
root.render(ready ? <App /> : <main style={{padding: 48}}><h1>金讯达</h1>
<p>请从统一门户登录并进入金讯达。</p><a href={portalHome}>返回统一门户</a></main>);
if (ready && portalMode) {
let checking = false;
setInterval(async () => {
if (checking) return;
checking = true;
try {
const response = await fetch('/api/portal/session', { cache: 'no-store' });
if (!response.ok) window.location.replace(portalHome);
} catch { window.location.replace(portalHome); }
finally { checking = false; }
}, 10000);
}
});
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(<App />);
postMessage({ payload: "removeLoading" }, "*");
+1 -2
View File
@@ -1,6 +1,5 @@
import { Layout } from "antd";
import { useTranslation } from "react-i18next";
import { portalMode } from "@/portal";
export const EmptyChat = () => {
const { t } = useTranslation();
@@ -16,7 +15,7 @@ export const EmptyChat = () => {
/>
</svg>
</div>
<div className="mt-4 text-base font-medium">{portalMode ? '金讯达' : t("placeholder.title")}</div>
<div className="mt-4 text-base font-medium">{t("placeholder.title")}</div>
<div className="mt-1 text-xs text-[var(--sub-text)]">
{t("placeholder.subTitle")}
</div>
-3
View File
@@ -8,13 +8,10 @@ import { feedbackToast } from "@/utils/common";
import styles from "./index.module.scss";
import LoginForm from "./LoginForm";
import { portalMode, portalHome } from '@/portal';
export const Login = () => {
const [_, copyToClipboard] = useCopyToClipboard();
if (portalMode) return <main style={{padding: 48}}><p>登录已失效,请返回门户重新进入。</p><a href={portalHome}>返回统一门户</a></main>;
const handleCopy = () => {
copyToClipboard(`${`${APP_NAME} ${APP_VERSION}`}/${SDK_VERSION}`);
feedbackToast({ msg: t("toast.copySuccess") });
-20
View File
@@ -1,20 +0,0 @@
html[data-portal='true'] {
--primary: #b32635;
--primary-active: #f6e8e9;
--top-search-bar: #b32635;
--chat-bubble-sender: #f4dfe1;
.portal-header { height: 56px; display: flex; align-items: center; gap: 20px; padding: 0 24px; border-bottom: 1px solid var(--gap-text); background: #fff; }
.portal-header strong { color: var(--primary); font-size: 20px; }
.portal-header span { color: var(--sub-text); }
.portal-header a { margin-left: auto; color: var(--primary); }
.ant-spin-nested-loading, .ant-spin-container { height: 100%; }
&[data-theme='night'] {
color-scheme: dark;
--primary: #e2737d; --primary-active: #35272a; --base-black: #e9e5df;
--sub-text: #a8a29a; --gap-text: #3b3634; --search-bg: #292626;
--chat-bg: #201e1d; --chat-bubble: #312d2b; --chat-bubble-sender: #4b3034;
background: #201e1d;
.portal-header, .bg-white, .ant-layout { background: #252221 !important; }
input, textarea, .ant-input, .ant-modal-content, .ant-popover-inner { background: #292626; color: #e9e5df; }
}
}
-20
View File
@@ -1,20 +0,0 @@
import { setIMProfile, clearIMProfile } from './utils/storage';
export const portalMode = import.meta.env.VITE_PORTAL_MODE === '1';
export const portalHome = import.meta.env.VITE_PORTAL_URL || '';
export async function initializePortal(): Promise<boolean> {
if (!portalMode) return true;
try {
const response = await fetch('/api/portal/session', { cache: 'no-store', credentials: 'same-origin' });
if (!response.ok) throw new Error('Session expired');
const profile = await response.json();
await setIMProfile(profile);
document.documentElement.dataset.theme = profile.theme === 'night' ? 'night' : 'day';
document.documentElement.dataset.portal = 'true';
document.title = '金讯达 · 金牛集团';
return true;
} catch {
clearIMProfile();
return false;
}
}
+3 -1
View File
@@ -25,7 +25,9 @@ export const setIMProfile = ({
imToken: string;
userID: string;
}) => {
return Promise.all([setTMToken(imToken), setChatToken(chatToken), setTMUserID(userID)]);
setTMToken(imToken);
setChatToken(chatToken);
setTMUserID(userID);
};
export const setLocale = (locale: string) => localStorage.setItem("IM_LOCALE", locale);
-9
View File
@@ -1,9 +0,0 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'node:path';
export default defineConfig({
plugins: [react()],
resolve: { alias: { '@': path.resolve(__dirname, 'src') } },
build: { outDir: 'dist-portal', sourcemap: false },
});
+1
View File
@@ -43,3 +43,4 @@ docker compose \
echo "已提交 compose 启动。检查: docker compose -f docker-compose.yaml -f deploy/public/docker-compose.public.yaml ps"
echo "证书未就绪时先用 nginx.bootstrap.conf 申请证书,见 deploy/public/README.md"
echo "HEL-551 起 80/443 由系统 Nginx 持有,还需执行: ./scripts/switch-to-host-nginx.sh"
+11 -3
View File
@@ -1,11 +1,19 @@
#!/usr/bin/env bash
# 公网 overlay 回滚到内网 compose:停掉 edge,按原 docker-compose.yaml 拉起。
# 公网 overlay 回滚到内网 compose:按原 docker-compose.yaml 拉起。
# 不删除 components/ 与 data/,不改现网数据文件。
#
# HEL-551 后 80/443 由系统 Nginx 持有,日常 docker-compose.public.yaml 里已经
# 没有 edge 服务;这里额外叠上 docker-compose.edge-fallback.yaml,是为了兼容
# “当前处于 rollback-to-jxd-edge.sh 应急状态、jxd-edge 容器还在跑”这种情况,
# 确保它也能被一起清理。系统 Nginx 上的 jxd 站点文件不受本脚本影响,需要的话
# 用 scripts/rollback-to-jxd-edge.sh 或手工禁用。
set -euo pipefail
cd "$(dirname "$0")/.."
docker compose -f docker-compose.yaml -f deploy/public/docker-compose.public.yaml stop edge || true
docker compose -f docker-compose.yaml -f deploy/public/docker-compose.public.yaml rm -f edge || true
docker compose -f docker-compose.yaml -f deploy/public/docker-compose.public.yaml \
-f deploy/public/docker-compose.edge-fallback.yaml stop edge 2>/dev/null || true
docker compose -f docker-compose.yaml -f deploy/public/docker-compose.public.yaml \
-f deploy/public/docker-compose.edge-fallback.yaml rm -f edge 2>/dev/null || true
docker compose -f docker-compose.yaml up -d
+31
View File
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
# HEL-551:紧急回滚——系统 Nginx 让出 jxd.jinniu.ink 站点,jxd-edge 用 host
# 网络重新独占 80/443。由总工在服务器上执行;施工员本卡不跑本脚本。
#
# 用法: ./scripts/rollback-to-jxd-edge.sh
# 只禁用 jxd 这一个站点文件(改后缀 .disabled,不删除,不影响系统 Nginx
# 上的其他站点,例如 solsum.cn),然后重载系统 Nginx。
set -euo pipefail
cd "$(dirname "$0")/.."
HOST_NGINX_VHOST_DIR="${HOST_NGINX_VHOST_DIR:-/www/server/panel/vhost/nginx}"
HOST_NGINX_INIT="${HOST_NGINX_INIT:-/etc/init.d/nginx}"
SITE_CONF_NAME="jxd.jinniu.ink.conf"
echo "== 1/2 禁用系统 Nginx 上的 jxd.jinniu.ink 站点 =="
if [ -f "${HOST_NGINX_VHOST_DIR}/${SITE_CONF_NAME}" ]; then
mv "${HOST_NGINX_VHOST_DIR}/${SITE_CONF_NAME}" "${HOST_NGINX_VHOST_DIR}/${SITE_CONF_NAME}.disabled"
"$HOST_NGINX_INIT" reload 2>/dev/null || systemctl reload nginx 2>/dev/null || true
else
echo "未找到 ${HOST_NGINX_VHOST_DIR}/${SITE_CONF_NAME},跳过禁用步骤"
fi
echo "== 2/2 重新拉起 jxd-edge(host 网络,独占 80/443) =="
docker compose \
-f docker-compose.yaml \
-f deploy/public/docker-compose.public.yaml \
-f deploy/public/docker-compose.edge-fallback.yaml \
up -d edge
echo "回滚完成,jxd-edge 已重新接管 80/443。检查: docker compose ps"
echo "数据目录 components/ 与 data/ 未动。"
+104
View File
@@ -0,0 +1,104 @@
#!/usr/bin/env bash
# HEL-551:把公网 80/443 从 jxd-edge(host 网络容器)切换到系统/宝塔 Nginx。
# 由总工在服务器上执行;施工员本卡不跑本脚本,也不 SSH 改现网。
#
# 用法: ./scripts/switch-to-host-nginx.sh
# 失败时自动回滚到 jxd-edge;也可以随时手动跑 ./scripts/rollback-to-jxd-edge.sh。
#
# 执行前可以按实际环境覆盖这几个变量,默认按宝塔面板的常见路径:
# HOST_NGINX_VHOST_DIR 站点配置目录(宝塔: /www/server/panel/vhost/nginx)
# HOST_NGINX_BIN nginx 可执行文件,用来做 -t 语法检查
# HOST_NGINX_INIT initscript,用来启动/重载(宝塔一般装了 /etc/init.d/nginx)
# HOST_NGINX_PIDFILE 系统 Nginx 的 pid 文件(宝塔: /www/server/nginx/logs/nginx.pid)
set -euo pipefail
cd "$(dirname "$0")/.."
REPO_DIR="$(pwd)"
SITE_CONF_SRC="deploy/public/host-nginx/jxd.jinniu.ink.conf"
SITE_CONF_NAME="jxd.jinniu.ink.conf"
ACME_WEBROOT="${REPO_DIR}/deploy/public/acme"
DOWNLOADS_DIR="${REPO_DIR}/deploy/public/downloads"
HOST_NGINX_VHOST_DIR="${HOST_NGINX_VHOST_DIR:-/www/server/panel/vhost/nginx}"
HOST_NGINX_BIN="${HOST_NGINX_BIN:-/www/server/nginx/sbin/nginx}"
HOST_NGINX_INIT="${HOST_NGINX_INIT:-/etc/init.d/nginx}"
HOST_NGINX_PIDFILE="${HOST_NGINX_PIDFILE:-/www/server/nginx/logs/nginx.pid}"
# 判断"系统 Nginx 本尊"是否在跑,只认 pidfile 里的进程。
# 不能用裸 pgrep -x nginx:宿主机上还有别的 nginx 容器(如 solsum 首页容器的
# nginx -g daemon off),它们会让 pgrep 误报"系统 Nginx 已在跑",导致对已停止的
# 系统 Nginx 执行 reload(必然失败),80/443 陷入无人监听。
nginx_running() {
[ -f "$HOST_NGINX_PIDFILE" ] && kill -0 "$(cat "$HOST_NGINX_PIDFILE" 2>/dev/null)" 2>/dev/null
}
BACKUP_DIR="/root/jxd-nginx-switch-backup-$(date +%Y%m%d%H%M%S)"
rollback() {
echo "!! 切换失败,回滚到 jxd-edge" >&2
./scripts/rollback-to-jxd-edge.sh || true
exit 1
}
echo "== 1/5 备份系统 Nginx 站点目录、金讯达 compose、证书续期引用 =="
mkdir -p "$BACKUP_DIR"
if [ -d "$HOST_NGINX_VHOST_DIR" ]; then
cp -a "$HOST_NGINX_VHOST_DIR" "$BACKUP_DIR/vhost-nginx"
fi
cp -a docker-compose.yaml deploy/public/docker-compose.public.yaml "$BACKUP_DIR/"
if [ -f "/etc/letsencrypt/renewal/jxd.jinniu.ink.conf" ]; then
mkdir -p "$BACKUP_DIR/letsencrypt-renewal"
cp -a /etc/letsencrypt/renewal/jxd.jinniu.ink.conf "$BACKUP_DIR/letsencrypt-renewal/"
fi
echo "备份完成: $BACKUP_DIR"
echo "== 2/5 生成站点配置(替换 ACME webroot / downloads 占位符)=="
mkdir -p "$ACME_WEBROOT"
TMP_CONF="$(mktemp)"
sed -e "s#__JXD_ACME_WEBROOT__#${ACME_WEBROOT}#g" \
-e "s#__JXD_DOWNLOADS_DIR__#${DOWNLOADS_DIR}#g" \
"$SITE_CONF_SRC" > "$TMP_CONF"
if [ ! -d "$HOST_NGINX_VHOST_DIR" ]; then
echo "站点目录 $HOST_NGINX_VHOST_DIR 不存在,请先用 HOST_NGINX_VHOST_DIR= 指定正确路径" >&2
rm -f "$TMP_CONF"
exit 1
fi
cp "$TMP_CONF" "${HOST_NGINX_VHOST_DIR}/${SITE_CONF_NAME}"
rm -f "$TMP_CONF"
echo "== 3/5 校验系统 Nginx 配置语法(先检查,不合格立即退出,不动服务)=="
if ! "$HOST_NGINX_BIN" -t; then
echo "系统 Nginx 配置检查失败,移除新站点文件,不触碰任何服务" >&2
rm -f "${HOST_NGINX_VHOST_DIR}/${SITE_CONF_NAME}"
exit 1
fi
echo "== 4/5 停 jxd-edge,启动/重载系统 Nginx =="
docker compose -f docker-compose.yaml -f deploy/public/docker-compose.public.yaml \
-f deploy/public/docker-compose.edge-fallback.yaml stop edge 2>/dev/null || true
docker compose -f docker-compose.yaml -f deploy/public/docker-compose.public.yaml \
-f deploy/public/docker-compose.edge-fallback.yaml rm -f edge 2>/dev/null || true
if nginx_running; then
"$HOST_NGINX_INIT" reload || systemctl reload nginx || rollback
else
"$HOST_NGINX_INIT" start || systemctl start nginx || rollback
fi
sleep 1
if ! nginx_running; then
rollback
fi
echo "== 5/5 健康检查 =="
sleep 1
CODE="$(curl -sk -o /dev/null -w '%{http_code}' --max-time 5 https://jxd.jinniu.ink/ || echo 000)"
if [ "$CODE" = "000" ]; then
echo "https://jxd.jinniu.ink/ 无响应(code=$CODE)" >&2
rollback
fi
echo "切换完成。系统 Nginx 已独占 80/443,jxd-edge 已下线。"
echo "备份目录: $BACKUP_DIR"
echo "如需回滚: ./scripts/rollback-to-jxd-edge.sh"