diff --git a/00-init-tools.sh b/00-init-tools.sh index 00585fe..258065b 100755 --- a/00-init-tools.sh +++ b/00-init-tools.sh @@ -271,10 +271,6 @@ _install_pc_nginx_proxy() { return 1 fi - if [[ ! -f /app/pc/dist/index.html ]]; then - warn " /app/pc/dist/index.html 不存在;域名首页会不可用。请先执行: ./deploy-test/dt.sh pc-build" - fi - if ! _has nginx; then if _has apt-get; then apt-get update -y @@ -317,7 +313,7 @@ _install_pc_nginx_proxy() { info " 本机 Nginx 仅监听 TCP 80;curl -sS -H 'Host: ${proxy_domain}' http://127.0.0.1/nginx-health 应返回 ok" info " 外部推荐入口 https://${proxy_domain} 应由 LB/CDN/其它网关终止 HTTPS 后转发到本机 :80" info " 建议 .env.deploy-test 设置 PC_BACKEND_ORIGIN=https://${proxy_domain}" - info " PC 静态根目录: /app/pc/dist(请先执行 ./deploy-test/dt.sh pc-build)" + info " PC 前端入口: Nginx :80 → 127.0.0.1:5173(请先执行 ./deploy-test/07-start-frontend.sh pc)" info " 浏览器打开 https://${proxy_domain}/" } diff --git a/01-init-env.sh b/01-init-env.sh index 346a896..14883e4 100755 --- a/01-init-env.sh +++ b/01-init-env.sh @@ -104,10 +104,10 @@ CF_CUSTOMER_CODE=huonxouoa55ent9z TENCENT_SDK_APP_ID=20033091 TENCENT_SDK_SECRET_KEY=cceba44084aaa04f8c48a1858ffd5385875c3a5ec006d34278d9d3714b40e3b0 -# ── PC 客户端对接的后端公网地址(可选)─────────────────────────────────────── +# ── PC 客户端(Vite dev:web)对接的后端公网地址(可选)─────────────────────── # 通过域名访问 Nginx 反代(sudo ./deploy-test/00-init-tools.sh nginx)。 -# 填写 HTTPS 根地址,无末尾斜杠;Nginx 会将 / 指向 /app/pc/dist,并代理 API/WS。 -# ./deploy-test/08-build-pc.sh 构建 pc 时会 export VITE_*,覆盖 pc/.env,无需改 pc 目录 +# 填写 HTTPS 根地址,无末尾斜杠;Nginx 会将 / 代理到 pc dev:web :5173,并代理 API/WS。 +# ./deploy-test/07-start-frontend.sh 启动 pc 时会 export VITE_*,覆盖 pc/.env,无需改 pc 目录 # 若某路径与网关不一致,可单独覆盖:PC_VITE_API_URL / PC_VITE_WS_URL / PC_VITE_CHAT_URL / PC_VITE_USER_URL PC_PROXY_DOMAIN=cms-jack.imharry.work PC_BACKEND_ORIGIN=https://cms-jack.imharry.work diff --git a/07-start-frontend.sh b/07-start-frontend.sh index 1b28e8e..a731ddb 100755 --- a/07-start-frontend.sh +++ b/07-start-frontend.sh @@ -7,9 +7,9 @@ # ./07-start-frontend.sh # 只启动指定项目 # # 项目与端口: -# pc → 默认 yarn dev:web :5173(无 Electron,仅直连调试);本机要 Electron 时设 PC_ELECTRON=1 使用 yarn dev +# pc → 默认 yarn dev:web :5173(无 Electron);本机要 Electron 时设 PC_ELECTRON=1 使用 yarn dev # 后端地址:在 .env.deploy-test 设 PC_BACKEND_ORIGIN,启动时注入 VITE_*(不改 pc 目录) -# 域名入口由 Nginx 直接访问 /app/pc/dist,需先执行 08-build-pc.sh +# 域名入口由 Nginx 代理到 127.0.0.1:5173 # meetingh5 → React + Vite :5188 # h5 → Vue + Vite :3003 # cms → UMI Max :8001 @@ -205,8 +205,8 @@ if [[ "$TARGET" == "all" ]]; then echo "" echo -e "${BOLD}访问地址:${NC}" - echo " PC 域名入口: ${PC_BACKEND_ORIGIN%/}/ (外部 HTTPS → 本机 Nginx :80 → /app/pc/dist;先执行 ./deploy-test/dt.sh pc-build)" - echo " PC 直连调试: http://${DEPLOY_TEST_IP}:5173 (Vite dev;绕过 Nginx;Electron 用 PC_ELECTRON=1 或 pc 目录内 yarn dev)" + echo " PC: ${PC_BACKEND_ORIGIN%/}/ (外部 HTTPS → 本机 Nginx :80 → pc dev:web :5173)" + echo " PC 直连调试: http://${DEPLOY_TEST_IP}:5173 (绕过 Nginx;Electron 用 PC_ELECTRON=1 或 pc 目录内 yarn dev)" echo " H5: http://${DEPLOY_TEST_IP}:3003" echo " CMS: http://${DEPLOY_TEST_IP}:8001" echo " Build CMS: http://${DEPLOY_TEST_IP}:8002" diff --git a/08-build-pc.sh b/08-build-pc.sh deleted file mode 100755 index d80cb43..0000000 --- a/08-build-pc.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env bash -# ============================================================================= -# 08-build-pc.sh — 构建 PC Web 静态产物 -# -# 产物目录: /app/pc/dist -# Nginx 配置 deploy-test/nginx/openim-pc-proxy.conf 会直接访问该目录。 -# ============================================================================= -set -euo pipefail -source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common.sh" -init_dirs - -if [[ -f "$ENV_FILE" ]]; then - set -a - # shellcheck source=/dev/null - source "$ENV_FILE" - set +a -fi - -normalize_pc_proxy_env -init_script_log - -header "构建 PC Web 静态产物" - -PC_DIR="$ROOT_DIR/pc" -if [[ ! -d "$PC_DIR" ]]; then - error "pc 目录不存在: $PC_DIR" - exit 1 -fi - -if ! command -v yarn &>/dev/null; then - error "yarn 未安装,请先执行: ./deploy-test/00-init-tools.sh node" - exit 1 -fi - -if [[ ! -d "$PC_DIR/node_modules" ]]; then - error "pc/node_modules 不存在,请先执行: ./deploy-test/06-install-frontend.sh pc" - exit 1 -fi - -pc_ensure_wasm_assets -pc_export_vite_backend_env -pc_print_vite_backend_env - -step "执行 yarn build" -( - cd "$PC_DIR" - pc_export_vite_backend_env - yarn build -) - -if [[ ! -f "$PC_DIR/dist/index.html" ]]; then - error "构建失败: $PC_DIR/dist/index.html 不存在" - exit 1 -fi - -success "PC Web 构建完成: $PC_DIR/dist" -info "Nginx 静态根目录: /app/pc/dist" -info "重新加载 Nginx 配置: sudo ./deploy-test/00-init-tools.sh nginx" diff --git a/README.md b/README.md index 507a13a..d96ab20 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,6 @@ 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 pc-build # 构建 PC Web 静态产物到 /app/pc/dist ./deploy-test/dt.sh fe-start pc # 启动 pc 前端 ./deploy-test/dt.sh fe-stop pc # 停止 pc 前端 ./deploy-test/dt.sh up # pull + build + restart @@ -308,26 +307,26 @@ TENCENT_SDK_SECRET_KEY=xxx ### Nginx 反代(域名 HTTPS 入口,供 PC / 浏览器访问后端) -在**测试服务器**上部署 Nginx,本机 Nginx 仅监听 HTTP `:80`,直接访问 PC 构建产物 `/app/pc/dist`,并反代 OpenIM API、chat-api 与 MsgGateway WebSocket。外部访问仍使用 `https://cms-jack.imharry.work`,HTTPS 由外层 LB/CDN/其它网关终止后转发到本机 `:80`。 +在**测试服务器**上部署 Nginx,本机 Nginx 仅监听 HTTP `:80`,统一反代 PC Vite dev:web server、OpenIM API、chat-api 与 MsgGateway WebSocket。外部访问仍使用 `https://cms-jack.imharry.work`,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) | -| `/` | `/app/pc/dist`(PC Web 静态构建产物) | +| `/` | `127.0.0.1:5173`(PC Vite dev:web server) | 1. 服务器上已执行 `05-start.sh` 等,保证 `10001/10002/10008` 在监听。 2. 域名 `cms-jack.imharry.work` 已解析到测试服务器公网 IP。 3. `.env.deploy-test` 中设置 **`PC_BACKEND_ORIGIN=https://cms-jack.imharry.work`**(无末尾 `/`)。 -4. 仓库根目录执行:`./deploy-test/08-build-pc.sh` 或 `./deploy-test/dt.sh pc-build`,构建 `/app/pc/dist`。 +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://cms-jack.imharry.work/`**。 -**域名访问**:本配置中 `openim-pc-proxy` 使用 `server_name cms-jack.imharry.work`,只监听本机 `80`;推荐外部 `GET /` 走 `https://cms-jack.imharry.work/`,由外层 HTTPS 入口转发到本机 `80` 后读取 `/app/pc/dist`。`00-init-tools.sh nginx` 会禁用 `sites-enabled/default`,并尝试去掉 `sites-available/default` 里的 `default_server`,避免默认站点抢占 `:80`。若机上还有其它站点也写了 `default_server`,`nginx -t` 会报错,需在该站点配置中删除 `default_server`(保留 `listen 80;` 即可)。 +**域名访问**:本配置中 `openim-pc-proxy` 使用 `server_name cms-jack.imharry.work`,只监听本机 `80`;推荐外部 `GET /` 走 `https://cms-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 构建**:`08-build-pc.sh` 会在构建前注入 `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/dt.sh pc-build`。 +**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`。 ### Docker 基础设施 diff --git a/dt.sh b/dt.sh index d0638e4..638b3c0 100755 --- a/dt.sh +++ b/dt.sh @@ -46,7 +46,6 @@ deploy-test 后端/基础服务: status 调用 deploy-test/status.sh deploy-test 前端: - pc-build 调用 deploy-test/08-build-pc.sh,构建 /app/pc/dist fe-start [project] 调用 deploy-test/07-start-frontend.sh [project] fe-stop [project] 调用 deploy-test/stop-frontend.sh [project] @@ -60,7 +59,6 @@ deploy-test 前端: 示例: ./deploy-test/dt.sh pull ./deploy-test/dt.sh build - ./deploy-test/dt.sh pc-build ./deploy-test/dt.sh restart ./deploy-test/dt.sh fe-start pc ./deploy-test/dt.sh deploy @@ -191,9 +189,6 @@ main() { status) run_deploy_test_script "status.sh" "$@" ;; - pc-build) - run_deploy_test_script "08-build-pc.sh" "$@" - ;; fe-start) run_deploy_test_script "07-start-frontend.sh" "$@" ;; diff --git a/nginx/openim-pc-proxy.conf b/nginx/openim-pc-proxy.conf index b3e7463..6454b37 100644 --- a/nginx/openim-pc-proxy.conf +++ b/nginx/openim-pc-proxy.conf @@ -30,9 +30,6 @@ server { listen [::]:80; server_name cms-jack.imharry.work; - root /app/pc/dist; - index index.html; - client_max_body_size 100m; add_header Cross-Origin-Opener-Policy "same-origin" always; add_header Cross-Origin-Embedder-Policy "credentialless" always; @@ -113,8 +110,19 @@ server { return 200 "ok\n"; } - # PC 静态构建产物。 + # PC Vite dev:web server. location / { - try_files $uri $uri/ /index.html; + proxy_pass http://127.0.0.1:5173; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $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_cache_bypass $http_upgrade; + proxy_buffering off; + proxy_read_timeout 86400s; + proxy_send_timeout 86400s; } } diff --git a/status.sh b/status.sh index f5d90b5..1328153 100755 --- a/status.sh +++ b/status.sh @@ -76,7 +76,7 @@ if command -v curl &>/dev/null && [[ -n "${PC_BACKEND_ORIGIN:-}" ]]; then echo " PC Chat API: ${PC_VITE_CHAT_URL:-${PC_BACKEND_ORIGIN}/api/chat}" echo " PC Admin API: ${PC_VITE_ADMIN_URL:-${PC_BACKEND_ORIGIN}/api/admin}" echo " PC WebSocket: ${PC_VITE_WS_URL:-$default_ws_url}" - echo " PC 页面入口: ${PC_BACKEND_ORIGIN}/ (外部 HTTPS → 本机 Nginx :80 → /app/pc/dist)" + echo " PC 页面入口: ${PC_BACKEND_ORIGIN}/ (外部 HTTPS → 本机 Nginx :80 → pc dev:web :5173)" echo " Nginx 日志: /var/log/nginx/openim-pc-proxy-access.log" pc_probe_msg_gateway "$PC_BACKEND_ORIGIN" else