Files
2026-07-05 14:43:34 +08:00

32 lines
1.4 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 修 Nginx /uploads/ proxy_pass - 因为 nginx 在 docker 容器里, 127.0.0.1 不是宿主
# 改成 host.docker.internal (Docker Desktop) 或宿主 IP (Linux)
NGINX_SITE=/etc/nginx/sites-enabled/yuyueguahao
# 1) 确认宿主 IPbridge 网关通常 172.17.0.1
HOST_IP=$(ip route | grep default | awk '{print $3}' | head -1)
echo "Host IP (default gateway): $HOST_IP"
# 2) 测试哪个 IP 能连到 3000
echo "--- Test 127.0.0.1:3000 ---"
curl -s -o /dev/null -w "HTTP %{http_code}\n" --max-time 3 http://127.0.0.1:3000/api/v1/banners || echo "FAIL"
echo "--- Test $HOST_IP:3000 ---"
curl -s -o /dev/null -w "HTTP %{http_code}\n" --max-time 3 http://$HOST_IP:3000/api/v1/banners || echo "FAIL"
echo "--- Test host.docker.internal:3000 ---"
curl -s -o /dev/null -w "HTTP %{http_code}\n" --max-time 3 http://host.docker.internal:3000/api/v1/banners || echo "FAIL"
# 3) 改 nginx 配置
echo "--- Updating nginx config ---"
sed -i 's|proxy_pass http://127.0.0.1:3000;|proxy_pass http://'"$HOST_IP"':3000;|' "$NGINX_SITE"
grep -A3 uploads "$NGINX_SITE"
# 4) reload
NGINX_MASTER=$(ps -efL | grep "nginx: master" | grep -v grep | awk '{print $2}' | head -1)
echo "Reload nginx master PID: $NGINX_MASTER"
kill -HUP "$NGINX_MASTER"
sleep 2
# 5) 验证
echo "--- TEST 80 ---"
curl -o /dev/null -s -w "HTTP %{http_code} size=%{size_download} type=%{content_type}\n" http://localhost/uploads/1781403331659-1cac3cac.png