From 6c30dddbbefd83620f17ba62650029c88043f3a9 Mon Sep 17 00:00:00 2001 From: vet Date: Tue, 14 Apr 2026 11:05:46 +0700 Subject: [PATCH] test --- 07-start-frontend.sh | 6 +++-- common.sh | 31 ++++++++++++++++++++++ nginx/openim-pc-proxy.conf | 11 ++++++-- status.sh | 53 ++++++++++++++++++++++++++++++-------- 4 files changed, 86 insertions(+), 15 deletions(-) diff --git a/07-start-frontend.sh b/07-start-frontend.sh index 7263a88..daa5465 100755 --- a/07-start-frontend.sh +++ b/07-start-frontend.sh @@ -124,8 +124,10 @@ _start_fe() { fi info "启动 ${BOLD}$name${NC} ..." - if [[ "$name" == "pc" ]] && [[ -n "${PC_BACKEND_ORIGIN:-}" ]]; then - info " pc 后端 PC_BACKEND_ORIGIN=${PC_BACKEND_ORIGIN}(注入 VITE_*,不写 pc 目录)" + if [[ "$name" == "pc" ]]; then + pc_export_vite_backend_env + pc_print_vite_backend_env + pc_check_nginx_gateway fi # 写日志分隔符 diff --git a/common.sh b/common.sh index ce06edc..136d661 100755 --- a/common.sh +++ b/common.sh @@ -247,3 +247,34 @@ pc_export_vite_backend_env() { export VITE_WS_URL="${PC_VITE_WS_URL:-wss://${host}/msg_gateway}" fi } + +pc_print_vite_backend_env() { + if [[ -z "${PC_BACKEND_ORIGIN:-}" ]]; then + warn " pc 未设置 PC_BACKEND_ORIGIN,将使用 pc/.env 或代码默认地址;WebSocket 可能连错环境" + return 0 + fi + + info " pc 后端 PC_BACKEND_ORIGIN=${PC_BACKEND_ORIGIN}(注入 VITE_*,不写 pc 目录)" + info " VITE_API_URL=${VITE_API_URL:-}" + info " VITE_WS_URL=${VITE_WS_URL:-}" + info " VITE_CHAT_URL=${VITE_CHAT_URL:-}" + info " VITE_USER_URL=${VITE_USER_URL:-}" +} + +pc_check_nginx_gateway() { + local o="${PC_BACKEND_ORIGIN:-}" + o="${o%/}" + [[ -z "$o" ]] && return 0 + + if ! command -v curl &>/dev/null; then + warn " 未安装 curl,跳过 Nginx 网关检查;请手动访问 ${o}/nginx-health" + return 0 + fi + + if curl -fsS --max-time 3 "${o}/nginx-health" >/dev/null 2>&1; then + success " Nginx 网关可达: ${o}/nginx-health" + else + warn " Nginx 网关不可达: ${o}/nginx-health" + warn " PC WebSocket 默认连 ${VITE_WS_URL:-ws:///msg_gateway};请确认已执行 sudo ./deploy-test/00-init-tools.sh nginx,并放行 TCP 80" + fi +} diff --git a/nginx/openim-pc-proxy.conf b/nginx/openim-pc-proxy.conf index bf45810..1a0458a 100644 --- a/nginx/openim-pc-proxy.conf +++ b/nginx/openim-pc-proxy.conf @@ -13,6 +13,11 @@ # default_server:纯 IP 访问 http://x.x.x.x/ 时命中本 server(不做 CMS 静态站,仅 API 网关) # CMS 开发请用 http://IP:8001(UMI dev) +map $http_upgrade $connection_upgrade { + default upgrade; + '' close; +} + server { listen 80 default_server; listen [::]:80 default_server; @@ -64,12 +69,14 @@ server { } # MsgGateway WebSocket → openim-server :10001 - location /msg_gateway { + 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 Connection $connection_upgrade; proxy_set_header Host $host; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Port $server_port; 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; diff --git a/status.sh b/status.sh index f705a2b..2717232 100755 --- a/status.sh +++ b/status.sh @@ -9,7 +9,12 @@ # ============================================================================= set -euo pipefail source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common.sh" -load_env 2>/dev/null || true +if [[ -f "$ENV_FILE" ]]; then + set -a + # shellcheck source=/dev/null + source "$ENV_FILE" + set +a +fi header "服务运行状态" @@ -45,24 +50,50 @@ print_svc_status "livecloud" ":8080" print_svc_status "livestream" ":8888" print_svc_status "build-server" ":8281" +# ── Nginx API / WebSocket 网关 ───────────────────────────────────────────────── +echo "" +echo -e "${BOLD}[ Nginx 网关(PC API / WebSocket)]${NC}" +if command -v curl &>/dev/null && [[ -n "${PC_BACKEND_ORIGIN:-}" ]]; then + PC_BACKEND_ORIGIN="${PC_BACKEND_ORIGIN%/}" + if curl -fsS --max-time 3 "${PC_BACKEND_ORIGIN}/nginx-health" >/dev/null 2>&1; then + printf " ${GREEN}●${NC} %-14s %s\n" "nginx-health" "${PC_BACKEND_ORIGIN}/nginx-health" + else + printf " ${RED}○${NC} %-14s %s\n" "nginx-health" "${PC_BACKEND_ORIGIN}/nginx-health 不可达" + echo " 请执行: sudo ./deploy-test/00-init-tools.sh nginx,并确认安全组/防火墙放行 TCP 80" + fi + gateway_host=$(printf '%s' "$PC_BACKEND_ORIGIN" | sed -E 's#^https?://([^/]+).*#\1#') + if [[ "$PC_BACKEND_ORIGIN" == https://* ]]; then + default_ws_url="wss://${gateway_host}/msg_gateway" + else + default_ws_url="ws://${gateway_host}/msg_gateway" + fi + echo " PC WebSocket: ${PC_VITE_WS_URL:-$default_ws_url}" +else + printf " ${YELLOW}○${NC} %-14s %s\n" "nginx-health" "跳过(未安装 curl 或未设置 PC_BACKEND_ORIGIN)" +fi + # ── 前端服务 ───────────────────────────────────────────────────────────────── echo "" echo -e "${BOLD}[ 前端开发服务器 ]${NC}" -declare -A FE_PORT_MAP=( - [pc]="5173 (yarn dev:web)" - [meetingh5]="5188" - [h5]="3003" - [cms]="8001" - [build-cms]="8002" - [build-down]="8003" -) +fe_port_desc() { + case "$1" in + pc) echo "5173 (yarn dev:web)" ;; + meetingh5) echo "5188" ;; + h5) echo "3003" ;; + cms) echo "8001" ;; + build-cms) echo "8002" ;; + build-down) echo "8003" ;; + *) echo "?" ;; + esac +} for fe in pc meetingh5 h5 cms build-cms build-down; do pidfile="$PID_DIR/fe-${fe}.pid" logfile="$LOG_DIR/fe-${fe}.log" + port_desc="$(fe_port_desc "$fe")" if [[ -f "$pidfile" ]] && kill -0 "$(cat "$pidfile")" 2>/dev/null; then - printf " ${GREEN}●${NC} %-14s PID=%-7s :%s\n" "$fe" "$(cat "$pidfile")" "${FE_PORT_MAP[$fe]}" + printf " ${GREEN}●${NC} %-14s PID=%-7s :%s\n" "$fe" "$(cat "$pidfile")" "$port_desc" else - printf " ${RED}○${NC} %-14s 未运行 :%s\n" "$fe" "${FE_PORT_MAP[$fe]}" + printf " ${RED}○${NC} %-14s 未运行 :%s\n" "$fe" "$port_desc" fi done