diff --git a/common.sh b/common.sh index ac10e9f..4032f47 100755 --- a/common.sh +++ b/common.sh @@ -278,4 +278,39 @@ pc_check_nginx_gateway() { 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 + + pc_probe_msg_gateway "$o" +} + +pc_probe_msg_gateway() { + local o="${1:-${PC_BACKEND_ORIGIN:-}}" + o="${o%/}" + [[ -z "$o" ]] && return 0 + + if ! command -v curl &>/dev/null; then + return 0 + fi + + local local_code public_code tmp_body + tmp_body="${TMPDIR:-/tmp}/openim-msggateway-probe.$$" + + local_code=$(curl -sS -o "$tmp_body" -w "%{http_code}" --max-time 3 \ + "http://127.0.0.1:10001/msg_gateway" 2>/dev/null || true) + if [[ "$local_code" == "000" ]]; then + warn " MsgGateway 本机不可达: http://127.0.0.1:10001/msg_gateway(请确认 openim-server 正在监听 :10001)" + else + success " MsgGateway 本机可达: http://127.0.0.1:10001/msg_gateway (HTTP ${local_code},无 token 返回错误属正常)" + fi + + public_code=$(curl -sS -o "$tmp_body" -w "%{http_code}" --max-time 3 \ + "${o}/msg_gateway" 2>/dev/null || true) + if [[ "$public_code" == "000" ]]; then + warn " MsgGateway Nginx 入口不可达: ${o}/msg_gateway" + elif [[ "$public_code" == "502" || "$public_code" == "503" || "$public_code" == "504" ]]; then + warn " MsgGateway Nginx 入口返回 HTTP ${public_code}: ${o}/msg_gateway(Nginx 到 127.0.0.1:10001 可能不通)" + else + success " MsgGateway Nginx 入口可达: ${o}/msg_gateway (HTTP ${public_code},无 token 返回错误属正常)" + fi + + rm -f "$tmp_body" } diff --git a/status.sh b/status.sh index 89fe716..5d3c0f0 100755 --- a/status.sh +++ b/status.sh @@ -72,6 +72,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}" + pc_probe_msg_gateway "$PC_BACKEND_ORIGIN" else printf " ${YELLOW}○${NC} %-14s %s\n" "nginx-health" "跳过(未安装 curl 或未设置 PC_BACKEND_ORIGIN)" fi