fix(nginx): Podman 下弃用 127.0.0.11 resolver,启动前等待上游可达

Made-with: Cursor
This commit is contained in:
whm
2026-03-21 23:57:36 +08:00
parent 89cd8f83bc
commit 5bfdd04f21
3 changed files with 47 additions and 11 deletions

View File

@@ -0,0 +1,38 @@
#!/bin/sh
# 供 yh_nginx 容器:在官方 entrypoint 之前等待 Compose/Podman 网络内 web/admin/api 可访问。
# 解决 1) 启动瞬间 host not found2) Podman 无 127.0.0.11 时勿用 resolver+变量 proxy_pass否则 502/超时)。
set -e
MAX="${NGINX_WAIT_UPSTREAM_SEC:-90}"
echo "yh_nginx: waiting for upstream (web:80 admin:80 api:8088), max ${MAX}s..."
# 优先 HTTP 探测ICMP 在部分环境被禁);无 wget 时用 ping
ping_one() {
host="$1"
if ping -c1 -W2 "$host" >/dev/null 2>&1; then
return 0
fi
ping -c1 -w3 "$host" >/dev/null 2>&1
}
upstream_ok() {
host="$1"
port="$2"
path="${3:-/}"
if command -v wget >/dev/null 2>&1; then
wget -q -O/dev/null -T 3 "http://${host}:${port}${path}" 2>/dev/null && return 0
fi
ping_one "$host"
}
n=0
while [ "$n" -lt "$MAX" ]; do
# api 根路径常为 404用 /api/health与 yuheng.docker.conf 注释一致)
if upstream_ok web 80 / && upstream_ok admin 80 / && upstream_ok api 8088 /api/health; then
echo "yh_nginx: upstream OK, starting nginx..."
exec /docker-entrypoint.sh nginx -g 'daemon off;'
fi
n=$((n + 1))
sleep 1
done
echo "yh_nginx: timeout waiting for web/admin/api (check 容器是否在同一网络、api 是否监听 8088)" >&2
exit 1