#!/bin/bash # 为什么公网 GET 能通、POST 登记却是空响应? # # 被控端真正走的是 POST /v1/agent/register。 # 如果 POST 过不去,整个中转就是废的。 set -u URL=https://relay.xxmxxs.top BODY='{"deviceId":"diag-2","code":"482222","name":"诊断","version":"1.4.0"}' echo "===== 1. 本地 POST(对照,应该秒回)=====" timeout 10 curl -s -H 'User-Agent: LanRemote/1.4.0' \ -H 'Content-Type: application/json' -d "$BODY" \ http://127.0.0.1:8080/v1/agent/register 2>&1 | head -c 200 echo echo echo "===== 2. 公网 POST,连打 6 次,看每次的结果 =====" for i in $(seq 1 6); do C=$(timeout 25 curl -4 -s -o /tmp/post_out.txt -w '%{http_code}' \ -H 'User-Agent: LanRemote/1.4.0' \ -H 'Content-Type: application/json' -d "$BODY" \ "$URL/v1/agent/register" 2>/tmp/post_err.txt) C=${C:-000} printf " %d) HTTP %-4s 响应=%s\n" "$i" "$C" \ "$(head -c 90 /tmp/post_out.txt 2>/dev/null)" if [ -s /tmp/post_err.txt ]; then printf " 错误: %s\n" "$(head -c 120 /tmp/post_err.txt)" fi sleep 3 done echo echo "===== 3. 公网 GET,同样打 6 次 =====" for i in $(seq 1 6); do C=$(timeout 20 curl -4 -s -o /tmp/get_out.txt -w '%{http_code}' \ -H 'User-Agent: LanRemote/1.4.0' "$URL/v1/health" 2>/dev/null) printf " %d) HTTP %-4s body=%s\n" "$i" "${C:-000}" \ "$(head -c 60 /tmp/get_out.txt 2>/dev/null)" sleep 3 done echo echo "===== 4. 隧道日志里的服务端错误 =====" grep -iE 'Serve tunnel error|failed to serve|502|origin' \ /root/lanremote-relay/tunnel.log 2>/dev/null | tail -8 | sed 's/^/ /' echo echo "===== 5. relay 自己的日志(有没有收到请求)=====" journalctl -u lanremote-relay --no-pager -n 12 2>/dev/null \ | grep -viE 'Started|Stopped|Consumed' | tail -8 | sed 's/^/ /'