#!/bin/bash # 查为什么管理页 / 经隧道返回 502,但 /v1/health 正常。 # # 502 = Cloudflare 拿不到源站响应。如果本地直接访问 / 也不行, # 那就是中转渲染管理页有问题,跟隧道无关。 set -u BASE=http://127.0.0.1:8080 echo "===== 1. 本地直接访问 / =====" OUT=$(timeout 15 curl -s -w '\n%{http_code} %{size_download} %{time_total}' "$BASE/" 2>/dev/null) CODE=$(echo "$OUT" | tail -1) echo " 状态/大小/耗时: $CODE" echo " 内容开头:" echo "$OUT" | head -c 200 | sed 's/^/ /' echo echo "===== 2. 本地访问 /v1/health 对比 =====" OUT2=$(timeout 15 curl -s -w '\n%{http_code} %{size_download} %{time_total}' "$BASE/v1/health" 2>/dev/null) echo " 状态/大小/耗时: $(echo "$OUT2" | tail -1)" echo echo "===== 3. 本地访问 /?key=管理钥匙 =====" KEY=$(cat /root/lanremote-relay/data/admin_key.txt 2>/dev/null) OUT3=$(timeout 15 curl -s -w '\n%{http_code} %{size_download} %{time_total}' "$BASE/?key=$KEY" 2>/dev/null) echo " 状态/大小/耗时: $(echo "$OUT3" | tail -1)" echo " 内容开头:" echo "$OUT3" | head -c 200 | sed 's/^/ /' echo echo "===== 4. 经隧道访问 / =====" for i in 1 2 3; do OUT4=$(timeout 25 curl -4 -s -w '\n%{http_code} %{size_download} %{time_total}' \ -H 'User-Agent: LanRemote/1.4.0' https://relay.xxmxxs.top/ 2>/dev/null) printf " 第 %d 次: %s\n" "$i" "$(echo "$OUT4" | tail -1)" sleep 3 done echo echo "===== 5. 经隧道访问 /v1/health =====" for i in 1 2 3; do C=$(timeout 20 curl -4 -s -o /dev/null -w '%{http_code}' \ -H 'User-Agent: LanRemote/1.4.0' https://relay.xxmxxs.top/v1/health 2>/dev/null) printf " 第 %d 次: HTTP %s\n" "$i" "${C:-超时}" sleep 2 done echo echo "===== 6. 中转日志尾部(有没有异常)=====" tail -15 /root/lanremote-relay/relay.log 2>/dev/null | sed 's/^/ /' || echo " (没有日志)" echo echo "===== 7. 中转进程 =====" systemctl is-active lanremote-relay ps -o rss=,etime=,cmd= -p "$(systemctl show lanremote-relay -p MainPID | cut -d= -f2)" 2>/dev/null | sed 's/^/ /' echo echo "===== 8. 结论 =====" LOCAL_CODE=$(timeout 15 curl -s -o /dev/null -w '%{http_code}' "$BASE/" 2>/dev/null) TUNNEL_CODE=$(timeout 25 curl -4 -s -o /dev/null -w '%{http_code}' \ -H 'User-Agent: LanRemote/1.4.0' https://relay.xxmxxs.top/ 2>/dev/null) echo " 本地 / -> $LOCAL_CODE" echo " 隧道 / -> $TUNNEL_CODE" if [ "$LOCAL_CODE" = "200" ] && [ "$TUNNEL_CODE" != "200" ]; then echo " -> 本地好的,隧道不行。管理页比 health 大," echo " 可能是这条线路传大响应不稳定。" elif [ "$LOCAL_CODE" != "200" ]; then echo " -> 本地就不行,是中转的问题" fi