This commit is contained in:
vet
2026-04-21 12:24:04 +07:00
parent 67ab5f5ba5
commit 6eb89ad2a9
15 changed files with 421 additions and 170 deletions

View File

@@ -103,7 +103,8 @@ deploy-test/
./deploy-test/dt.sh stop # 停止 deploy-test 后端服务
./deploy-test/dt.sh restart # 重启 deploy-test 后端服务
./deploy-test/dt.sh status # 查看服务状态
./deploy-test/dt.sh fe-start pc # 启动 pc 前端
./deploy-test/dt.sh fe-build-static pc # 构建 pc 静态前端
./deploy-test/dt.sh fe-verify-static # 验证静态前端域名入口
./deploy-test/dt.sh fe-stop pc # 停止 pc 前端
./deploy-test/dt.sh up # pull + build + restart
./deploy-test/dt.sh deploy # pull + build + restart + status
@@ -181,13 +182,18 @@ vim .env.deploy-test
# 7. 安装前端依赖(可选)
./deploy-test/06-install-frontend.sh
# 8. 启动前端开发服务器(可选)
# 8. 构建静态前端pc/cms/build-cms/build-down可选)
./deploy-test/08-build-static-frontend.sh
# 9. 启动开发态前端meetingh5/h5可选
./deploy-test/07-start-frontend.sh
```
> **pcElectron依赖安装****优先**按上文配置 **GitHub SSH 密钥**;裸机还需 **`00-init-tools.sh`**(见「步骤 0」。若仍无法用 SSH再依赖脚本内的 GitHub **HTTPS 重写**。详见「pc 前端 yarn install 失败」。`pc` 建议仅用 **Yarn**;可删除 `package-lock.json` 消除混用锁文件警告。
> **`07-start-frontend.sh`**启动前会读取 `.env.deploy-test`(若存在),文末「访问地址」等处使用 `DEPLOY_TEST_IP`;未设置时默认为 `127.0.0.1`,避免脚本在 `set -u` 下因未定义变量退出
> **`08-build-static-frontend.sh`**构建前会读取 `.env.deploy-test`(若存在),其中 `pc` 会注入 `VITE_*` 并确保 wasm 资源存在
>
> **`07-start-frontend.sh`**:现在只用于 `meetingh5`、`h5` 这类开发态前端。
---
@@ -282,14 +288,23 @@ TENCENT_SDK_SECRET_KEY=xxx
### 前端开发服务器(可选)
**开发态前端**
| 项目 | 端口 | 说明 |
|------|------|------|
| pc (Electron) | :7777 | Electron 桌面客户端 |
| meetingh5 | :5188 | 直播观看 H5弹幕+视频) |
| h5 | :3003 | 移动端 H5 |
| cms | :8001 | 后台管理 |
| build-cms | :8002 | 构建管理后台 |
| build-down | :8003 | 下载页 |
**静态站点**
| 项目 | 访问地址 | 说明 |
|------|----------|------|
| pc | `https://pc-jack.imharry.work/` | Nginx -> `/app/pc/dist` |
| cms | `http://cms-jack.imharry.work/` | Nginx -> `/app/cms/dist` |
| build-cms | `http://build-jack.imharry.work/` | Nginx -> `/app/build-cms/dist` |
| build-down | `http://down-jack.imharry.work/` | Nginx -> `/app/build-down/dist` |
> `pc`、`build-down` 在 `deploy-test` 中都按静态站点方式提供,不再通过 `07-start-frontend.sh` 起 Web dev server。若需要 Electron 桌面端调试,请进入 `pc/` 目录单独执行项目自身命令。
> **meetingh5 访问方式**
>
@@ -308,26 +323,56 @@ TENCENT_SDK_SECRET_KEY=xxx
### Nginx 反代(域名 HTTPS 入口,供 PC / 浏览器访问后端)
在**测试服务器**上部署 Nginx本机 Nginx 仅监听 HTTP `:80`,统一反代 PC Vite dev:web server、OpenIM API、chat-api 与 MsgGateway WebSocket。外部访问仍使用 `https://pc-jack.imharry.work`HTTPS 由外层 LB/CDN/其它网关终止后转发到本机 `:80`
在**测试服务器**上部署 Nginx本机 Nginx 仅监听 HTTP `:80`,统一提供 PC/CMS/Build-CMS 的静态 `dist` 资源,并反代 OpenIM API、chat-api、admin-api、build-server 与 MsgGateway WebSocket。外部访问仍使用对应域名HTTPS 由外层 LB/CDN/其它网关终止后转发到本机 `:80`
| 路径前缀 | 后端 |
|----------|------|
| `/api/im/` | `127.0.0.1:10002` |
| `/api/user/``/api/chat/` | `127.0.0.1:10008` |
| `/msg_gateway` | `127.0.0.1:10001`WebSocket |
| `/` | `127.0.0.1:5173`PC Vite dev:web server |
| `Host: pc-jack.imharry.work /` | `/app/pc/dist` |
| `Host: cms-jack.imharry.work /` | `/app/cms/dist` |
| `Host: build-jack.imharry.work /` | `/app/build-cms/dist` |
| `Host: down-jack.imharry.work /` | `/app/build-down/dist` |
1. 服务器上已执行 `05-start.sh` 等,保证 `10001/10002/10008` 在监听。
2. 域名 `pc-jack.imharry.work` 已解析到测试服务器公网 IP。
3. `.env.deploy-test` 中设置 **`PC_BACKEND_ORIGIN=https://pc-jack.imharry.work`**(无末尾 `/`)。
4. 仓库根目录执行:`./deploy-test/07-start-frontend.sh pc``./deploy-test/dt.sh fe-start pc`启动 PC Vite dev:web server
5. 仓库根目录执行:`sudo ./deploy-test/00-init-tools.sh nginx`(会安装 `nginx`,并写入配置 `deploy-test/nginx/openim-pc-proxy.conf`;亦已包含在 `00-init-tools.sh` 无参的 **all** 流程末尾,需 root
6. 测试服务器本机/安全组放行 **TCP 80**;外层 LB/CDN/网关对公网提供 HTTPS `443` 并转发到本机 `80`
7. 浏览器打开 **`https://pc-jack.imharry.work/`**
4. 仓库根目录执行:`./deploy-test/08-build-static-frontend.sh pc``./deploy-test/dt.sh fe-build-static pc`构建 PC 静态资源
5. 如需同时构建 PC / CMS / Build-CMS / Build-Down可直接执行`./deploy-test/08-build-static-frontend.sh`;也可分别构建单个项目
6. 仓库根目录执行:`sudo ./deploy-test/00-init-tools.sh nginx`(会安装 `nginx`,并写入配置 `deploy-test/nginx/openim-pc-proxy.conf`;亦已包含在 `00-init-tools.sh` 无参的 **all** 流程末尾,需 root
7. 执行:`./deploy-test/09-verify-static-frontends.sh`,确认 `dist` 和域名入口都正常
8. 测试服务器本机/安全组放行 **TCP 80**;外层 LB/CDN/网关对公网提供 HTTPS `443` 并转发到本机 `80`
9. 浏览器打开 **`https://pc-jack.imharry.work/`**、**`http://cms-jack.imharry.work/`**、**`http://build-jack.imharry.work/`**、**`http://down-jack.imharry.work/`**。
**域名访问**:本配置中 `openim-pc-proxy` 使用 `server_name pc-jack.imharry.work`,只监听本机 `80`;推荐外部 `GET /``https://pc-jack.imharry.work/`,由外层 HTTPS 入口转发到本机 `80` 后代理 PC Vite dev:web。`00-init-tools.sh nginx` 会禁用 `sites-enabled/default`,并尝试去掉 `sites-available/default` 里的 `default_server`,避免默认站点抢占 `:80`。若机上还有其它站点也写了 `default_server``nginx -t` 会报错,需在该站点配置中删除 `default_server`(保留 `listen 80;` 即可)。
**推荐验收命令**
**PC dev:web**`07-start-frontend.sh pc` 会在启动前注入 `VITE_API_URL``VITE_WS_URL``VITE_CHAT_URL``VITE_USER_URL` 等变量,并确保 `openIM.wasm``sql-wasm.wasm``wasm_exec.js` 存在于 `pc/public`。更新 `pc` 代码或 `.env.deploy-test` 后,需要重启 PC 前端:`./deploy-test/stop-frontend.sh pc && ./deploy-test/07-start-frontend.sh pc`
```bash
# 1. 构建全部静态前端
./deploy-test/08-build-static-frontend.sh
# 2. 安装 / 更新 nginx 配置并立即校验 Host 路由
sudo ./deploy-test/00-init-tools.sh nginx
# 3. 统一校验 dist / nginx-health / 首页 HTML / title
./deploy-test/09-verify-static-frontends.sh
# 4. 查看当前状态(包含静态站点 title 摘要)
./deploy-test/status.sh
# 5. 本机直连 nginx 做 Host 路由抽样
curl -H 'Host: pc-jack.imharry.work' http://127.0.0.1/ | head
curl -H 'Host: cms-jack.imharry.work' http://127.0.0.1/ | head
curl -H 'Host: build-jack.imharry.work' http://127.0.0.1/ | head
curl -H 'Host: down-jack.imharry.work' http://127.0.0.1/ | head
# 或者直接走一条命令(需 root / sudo
sudo ./deploy-test/dt.sh fe-publish
```
**域名访问**:本配置中 `openim-pc-proxy` 使用 `server_name pc-jack.imharry.work``cms-jack.imharry.work``build-jack.imharry.work``down-jack.imharry.work`,只监听本机 `80`;推荐外部域名流量经 HTTPS 入口转发到本机 `80` 后由 Nginx 分发到对应静态站点与后端 API。`00-init-tools.sh nginx` 会禁用 `sites-enabled/default`,并尝试去掉 `sites-available/default` 里的 `default_server`,避免默认站点抢占 `:80`。若机上还有其它站点也写了 `default_server``nginx -t` 会报错,需在该站点配置中删除 `default_server`(保留 `listen 80;` 即可)。
**PC 静态构建**`08-build-static-frontend.sh pc` 会在构建前注入 `VITE_API_URL``VITE_WS_URL``VITE_CHAT_URL``VITE_USER_URL` 等变量,并确保 `openIM.wasm``sql-wasm.wasm``wasm_exec.js` 存在于 `pc/public`。更新 `pc` 代码或 `.env.deploy-test` 后,需要重新构建:`./deploy-test/08-build-static-frontend.sh pc`
### Docker 基础设施