#!/bin/bash # 502 但隧道连着 -> 回源这一段的问题。逐一排除。 set -u echo "════════ 1. 隧道 ingress 全文 ════════" cat /root/.cloudflared/config.yml 2>/dev/null | sed 's/^/ /' echo echo "════════ 2. relay 在听哪个地址 ════════" ss -lntp 2>/dev/null | grep -E ':8080' | sed 's/^/ /' echo echo "════════ 3. 带 Host 头访问(模拟云隧道回源)════════" for host in "relay.xxmxxs.top" "127.0.0.1" "localhost" ""; do if [ -z "$host" ]; then code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 8 http://127.0.0.1:8080/v1/health) echo " 不带 Host: HTTP $code" else code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 8 -H "Host: $host" http://127.0.0.1:8080/v1/health) echo " Host: $host -> HTTP $code" fi done echo echo "════════ 4. 请求 /(官网)带 Host 头 ════════" for host in "relay.xxmxxs.top" "127.0.0.1"; do printf " Host: %-22s HTTP %s\n" "$host" \ "$(curl -s -o /dev/null -w '%{http_code}' --max-time 8 -H "Host: $host" http://127.0.0.1:8080/)" done echo echo "════════ 5. 隧道进程的真实参数 ════════" pid=$(pgrep -f 'cloudflared tunnel' | head -1) [ -n "$pid" ] && tr '\0' ' ' < /proc/$pid/cmdline 2>/dev/null | sed 's/^/ /' echo echo "════════ 6. cloudflared 有没有报回源错误 ════════" tail -400 /root/lanremote-relay/tunnel.log 2>/dev/null \ | grep -iE 'origin|502|refused|unreachable|no such host|proxy' | tail -10 | sed 's/^/ /' echo " (没输出=没有回源错误)" echo echo "════════ 7. relay 自己有没有收到隧道来的请求 ════════" tail -60 /root/lanremote-relay/relay.log 2>/dev/null \ | grep -E 'GET|POST|处理' | tail -10 | sed 's/^/ /' echo echo "════════ 8. 关键:直接问 Cloudflare 边缘这个域名该怎么走 ════════" echo " DNS 记录:" getent hosts relay.xxmxxs.top | sed 's/^/ /' echo " HTTP 响应头(看 cf-ray / server):" curl -sI --max-time 20 -H 'User-Agent: LanRemote/1.4.0' https://relay.xxmxxs.top/v1/health \ | head -12 | sed 's/^/ /' echo echo "════════ 9. 换一个路径试(避开 /v1/health)════════" for p in "/" "/favicon.ico" "/v1/health" "/v1/downloads"; do printf " %-16s HTTP %s\n" "$p" \ "$(curl -s -o /dev/null -w '%{http_code}' --max-time 20 -H 'User-Agent: LanRemote/1.4.0' "https://relay.xxmxxs.top$p")" done