From d28671b60ca4c16d30d4680f9a6fc539f00da99e Mon Sep 17 00:00:00 2001 From: sky121113 Date: Fri, 16 Jan 2026 08:39:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=85=8D=E7=BD=AE=E7=AB=AF=E5=8F=A3?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E8=88=87=20TrustProxies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bootstrap/app.php | 4 ++++ compose.yaml | 5 +++-- nginx/demo-proxy.conf | 35 +++++++++++++++++++---------------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/bootstrap/app.php b/bootstrap/app.php index c194374..73e4de9 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -3,10 +3,14 @@ use Illuminate\Foundation\Application; use Illuminate\Foundation\Configuration\Exceptions; use Illuminate\Foundation\Configuration\Middleware; +use Illuminate\Http\Middleware\TrustProxies; use Symfony\Component\HttpKernel\Exception\HttpException; use Spatie\Permission\Exceptions\UnauthorizedException; use Inertia\Inertia; +// 信任所有代理(用於反向代理環境) +TrustProxies::at('*'); + return Application::configure(basePath: dirname(__DIR__)) ->withRouting( web: __DIR__.'/../routes/web.php', diff --git a/compose.yaml b/compose.yaml index 45c3e83..cf2aaea 100644 --- a/compose.yaml +++ b/compose.yaml @@ -11,7 +11,7 @@ services: extra_hosts: - 'host.docker.internal:host-gateway' ports: - - '${APP_PORT:-8080}:80' + # - '${APP_PORT:-8080}:80' # 由 proxy 處理 - '${VITE_PORT:-5173}:${VITE_PORT:-5173}' environment: WWWUSER: '${WWWUSER}' @@ -75,7 +75,8 @@ services: image: 'nginx:alpine' container_name: star-erp-proxy ports: - - '80:80' + - '8080:8080' + - '8081:8081' volumes: - './nginx/demo-proxy.conf:/etc/nginx/conf.d/default.conf:ro' networks: diff --git a/nginx/demo-proxy.conf b/nginx/demo-proxy.conf index e75dccd..526ba6f 100644 --- a/nginx/demo-proxy.conf +++ b/nginx/demo-proxy.conf @@ -1,26 +1,29 @@ +# 總後台 (landlord) - 端口 8080 server { - listen 80; + listen 8080; server_name 192.168.0.103; - # koori 租戶 - location /koori { - proxy_pass http://star-erp-laravel:80; - proxy_set_header Host koori.star-erp.demo:8080; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - - # 移除路徑前綴 - rewrite ^/koori/(.*) /$1 break; - rewrite ^/koori$ / break; - } - - # 總後台(預設) location / { proxy_pass http://star-erp-laravel:80; - proxy_set_header Host star-erp.demo:8080; + proxy_set_header Host star-erp.demo; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host:$server_port; + } +} + +# koori 租戶 - 端口 8081 +server { + listen 8081; + server_name 192.168.0.103; + + location / { + proxy_pass http://star-erp-laravel:80; + proxy_set_header Host koori.star-erp.demo; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host:$server_port; } }