From 5bd846ae62e7572f2d94d1993264f90c50fb45a7 Mon Sep 17 00:00:00 2001 From: lion <120344285@qq.com> Date: Tue, 18 Aug 2026 15:10:58 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E6=AC=A1=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Middleware/TrustProxies.php | 10 +++++++++- app/Providers/AppServiceProvider.php | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/Http/Middleware/TrustProxies.php b/app/Http/Middleware/TrustProxies.php index 559dd2f..b283ca3 100644 --- a/app/Http/Middleware/TrustProxies.php +++ b/app/Http/Middleware/TrustProxies.php @@ -12,7 +12,7 @@ class TrustProxies extends Middleware * * @var array|string|null */ - protected $proxies = '*'; + protected $proxies; /** * The headers that should be used to detect proxies. @@ -25,4 +25,12 @@ class TrustProxies extends Middleware Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO | Request::HEADER_X_FORWARDED_AWS_ELB; + + public function handle($request, \Closure $next) + { + // 本地 APP_URL 为 http 时不信任 X-Forwarded-Proto,避免首页/登录链接被拼成 https + $this->proxies = str_starts_with((string) config('app.url'), 'https://') ? '*' : []; + + return parent::handle($request, $next); + } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 1823ad7..d9054f2 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -27,7 +27,7 @@ class AppServiceProvider extends ServiceProvider */ public function boot(): void { - if (app()->environment('production') || str_starts_with((string) config('app.url'), 'https://')) { + if (str_starts_with((string) config('app.url'), 'https://')) { URL::forceScheme('https'); } }