From 5de47b570154e9a982969bf9b5b89769b04b1df8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=96=8C?= <259278618@qq.com> Date: Fri, 26 Jun 2026 15:58:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=90=E7=BB=B4=E8=84=9A=E6=9C=AC=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 12 ++++++++++++ ngnix.conf | 12 ++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 111173d..d979544 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,6 +24,18 @@ COPY ngnix.conf /etc/nginx/conf.d/default.conf # 复制SSL证书 COPY ssl/* /etc/nginx/ssl/ +# 启动时自动获取宿主机内网 IP,替换 __API_HOST__ 占位符 +RUN printf '%s\n' \ + '#!/bin/sh' \ + 'set -e' \ + 'if [ -n "$API_HOST" ]; then' \ + ' HOST_IP="$API_HOST"' \ + 'else' \ + ' HOST_IP=$(route -n 2>/dev/null | grep "^0.0.0.0" | tr -s " " | cut -d " " -f2)' \ + 'fi' \ + 'sed -i "s/__API_HOST__/$HOST_IP/g" /etc/nginx/conf.d/default.conf' \ + > /docker-entrypoint.d/01-set-api-host.sh && chmod +x /docker-entrypoint.d/01-set-api-host.sh + EXPOSE 80 443 CMD ["nginx", "-g", "daemon off;"] diff --git a/ngnix.conf b/ngnix.conf index 755a2be..583b611 100644 --- a/ngnix.conf +++ b/ngnix.conf @@ -19,7 +19,7 @@ server { listen 80; server_name minio.redpowerfuture.com; location / { - proxy_pass http://192.168.0.83:9000; + proxy_pass http://__API_HOST__:9001; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; @@ -33,7 +33,7 @@ server { listen 80; server_name consul.redpowerfuture.com; location / { - proxy_pass http://192.168.0.83:8500; + proxy_pass http://__API_HOST__:8500; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; @@ -47,7 +47,7 @@ server { listen 80; server_name meilisearch.redpowerfuture.com; location / { - proxy_pass http://192.168.0.83:7700; + proxy_pass http://__API_HOST__:7700; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; @@ -73,7 +73,7 @@ server { listen 80; server_name jaeger.redpowerfuture.com; location / { - proxy_pass http://192.168.0.83:16686; + proxy_pass http://__API_HOST__:16686; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; @@ -132,7 +132,7 @@ server { return 404; } - proxy_pass http://192.168.0.83:8000; + proxy_pass http://__API_HOST__:8000; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; @@ -178,7 +178,7 @@ server { ssl_ciphers HIGH:!aNULL:!MD5; location / { - proxy_pass http://192.168.0.83:9000; + proxy_pass http://__API_HOST__:9001; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr;