Laravel中使用负载均衡器和TrustedProxies的request()不安全

时间:2018-09-07 22:19:50

标签: laravel load-balancing laravel-forge

为什么request()->isSecure()在访问HTTPS网址时返回false?我正在使用Laravel Forge,并且有一个负载平衡器。记录请求,我得到以下数据:

request()->url(),          // "http://xx.xx"
request()->isSecure(),     // false
request()->getClientIps(), // XX.XX.XX.XX 

TrustProxies中(已添加到$middleware的{​​{1}}数组中):

Http/Kernel.php

在我的protected $proxies = [ 'XX.XX.XX.XX', // exactly the same as in the logged data above ]; 的{​​{1}}方法中:

AppServiceProvider

编辑:

我也在使用Cloudflare,并且我还将所有Cloudflare代理都添加到了boot()中。检查日志,我在请求中看到这些标题:

if (env('APP_ENV') == 'production') {
    \URL::forceScheme('https');
}

1 个答案:

答案 0 :(得分:1)

当您使用 Cloudflare 时,您应该使用“完全 SSL/TLS 加密模式”。