This commit is contained in:
Yvan
2026-09-23 17:42:55 +08:00
parent ac42e25868
commit 546cb49fec
4 changed files with 83 additions and 11 deletions
+9 -2
View File
@@ -26,7 +26,7 @@ FRONTEND_PORT=9501 # admin 管理后台 nginx 容器
BACKEND_PORT=9502 # 后端 API/WebSocket 容器
LIVEWEB_PORT=9503 # live 用户端(PC 直播页) nginx 容器
LIVE_UDP_PORT="${KRA_LIVE_UDP_PORT:-9504}" # WebRTC 音视频固定 UDP 端口(与 9501-9503 顺延配套)
LIVE_PUBLIC_IP="${KRA_LIVE_PUBLIC_IP:-}" # 留空时从站点域名解析
LIVE_PUBLIC_IP="${KRA_LIVE_PUBLIC_IP:-192.168.2.226}" # 留空时从站点域名解析
LIVE_HOST="${KRA_LIVE_HOST:-live.fuhua91.com}"
NETWORK="live-net"
BACKEND_NAME="live-backend"
@@ -53,7 +53,14 @@ if [ ! -f "$CONFIG_DIR/config.yaml" ]; then
fi
if [ -z "$LIVE_PUBLIC_IP" ]; then
LIVE_PUBLIC_IP="$(getent ahostsv4 "$LIVE_HOST" | awk 'NR == 1 { print $1 }')"
# 1) 域名解析,过滤内网/回环地址(服务器 /etc/hosts 可能指向内网)
LIVE_PUBLIC_IP="$(getent ahostsv4 "$LIVE_HOST" | awk '{print $1}' | grep -E '^[0-9]+(\.[0-9]+){3}$' \
| grep -vE '^(10\.|127\.|169\.254\.|172\.(1[6-9]|2[0-9]|3[01])\.|192\.168\.)' | head -n1)"
fi
if [ -z "$LIVE_PUBLIC_IP" ]; then
# 2) 域名取不到公网 IP 时,回退查询公网出口 IP(云主机 EIP 1:1 NAT 场景一致)
LIVE_PUBLIC_IP="$(curl -4 -fsS --max-time 5 https://api.ipify.org 2>/dev/null \
|| curl -4 -fsS --max-time 5 https://ifconfig.me 2>/dev/null || true)"
fi
if ! printf '%s' "$LIVE_PUBLIC_IP" | grep -Eq '^[0-9]+(\.[0-9]+){3}$'; then
echo "错误: 无法确定直播服务公网 IPv4,请通过 KRA_LIVE_PUBLIC_IP 显式设置"