From 40d4de90179a579e15574c4a77fd7b7b66a842fe Mon Sep 17 00:00:00 2001 From: whyour Date: Sun, 17 May 2026 23:43:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20localhost=20=E6=A3=80?= =?UTF-8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 5 +++++ back/schedule/health.ts | 2 +- back/shared/pLimit.ts | 2 +- docker/310.Dockerfile | 2 +- docker/Dockerfile | 2 +- docker/docker-entrypoint.sh | 10 ++++++++++ 6 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 0832167e..f86264af 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,11 @@ GRPC_PORT=5500 BACK_PORT=5700 +# 服务绑定地址,默认 ::(IPv6 通配,双栈系统同时支持 IPv4/IPv6) +# 纯 IPv4 环境自动 fallback 到 0.0.0.0,也可手动指定 +# BIND_HOST=0.0.0.0 +# BIND_HOST_GRPC=0.0.0.0 + LOG_LEVEL='info' JWT_SECRET= diff --git a/back/schedule/health.ts b/back/schedule/health.ts index f77a914b..dc90f7e6 100644 --- a/back/schedule/health.ts +++ b/back/schedule/health.ts @@ -10,7 +10,7 @@ const check = async ( switch (call.request.service) { case 'cron': const res = await promiseExec( - `curl -s --noproxy '*' http://0.0.0.0:${config.port}/api/system`, + `curl -s --noproxy '*' http://localhost:${config.port}/api/system`, ); if (res.includes('200')) { diff --git a/back/shared/pLimit.ts b/back/shared/pLimit.ts index f84763ad..2f04d5be 100644 --- a/back/shared/pLimit.ts +++ b/back/shared/pLimit.ts @@ -37,7 +37,7 @@ class TaskLimit { concurrency: Math.max(os.cpus().length, 4), }); private client = new ApiClient( - `0.0.0.0:${config.grpcPort}`, + `localhost:${config.grpcPort}`, credentials.createInsecure(), { 'grpc.enable_http_proxy': 0 }, ); diff --git a/docker/310.Dockerfile b/docker/310.Dockerfile index fb690b57..f9cb29b7 100644 --- a/docker/310.Dockerfile +++ b/docker/310.Dockerfile @@ -84,6 +84,6 @@ COPY --from=builder /tmp/build/node_modules/. /ql/node_modules/ WORKDIR ${QL_DIR} HEALTHCHECK --interval=5s --timeout=2s --retries=20 \ - CMD curl -sf --noproxy '*' http://127.0.0.1:${QlPort:-5700}/api/health || exit 1 + CMD curl -sf --noproxy '*' http://localhost:${QlPort:-5700}/api/health || exit 1 ENTRYPOINT ["./docker/docker-entrypoint.sh"] diff --git a/docker/Dockerfile b/docker/Dockerfile index 5682ae9d..6cde05d9 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -84,6 +84,6 @@ COPY --from=builder /tmp/build/node_modules/. /ql/node_modules/ WORKDIR ${QL_DIR} HEALTHCHECK --interval=5s --timeout=2s --retries=20 \ - CMD curl -sf --noproxy '*' http://127.0.0.1:${QlPort:-5700}/api/health || exit 1 + CMD curl -sf --noproxy '*' http://localhost:${QlPort:-5700}/api/health || exit 1 ENTRYPOINT ["./docker/docker-entrypoint.sh"] diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index 5d784cc3..b0693fe3 100755 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -25,6 +25,16 @@ if [ -f /etc/alpine-release ]; then fi fi +# 确保 /etc/hosts 包含 localhost 解析(应对精简镜像或仅 IPv4/IPv6 环境) +if ! grep -qE '^127\.0\.0\.1[[:space:]]+.*localhost' /etc/hosts 2>/dev/null; then + echo "127.0.0.1 localhost" >> /etc/hosts + log_with_style "INFO" "🔧 0. 已添加 IPv4 localhost 解析" +fi +if ! grep -qE '^::1[[:space:]]+.*localhost' /etc/hosts 2>/dev/null; then + echo "::1 localhost ip6-localhost ip6-loopback" >> /etc/hosts + log_with_style "INFO" "🔧 0. 已添加 IPv6 localhost 解析" +fi + log_with_style "INFO" "🚀 1. 检测配置文件..." load_ql_envs export_ql_envs