Laravel application settings for Load-balancer or Proxy Server
If your laravel application is running behind the Proxy Server or the Load-Balancer then you should follow these settings.
Even, if the proxy server or Load-balancer receives https:// requests from global users and your app server receives http:// requests from the proxy or LB then you should follow these steps too.
- You need to allow the proxies. To allow all proxies enter the follwing codes in your ./bootstrap/app.php file.
->withMiddleware(function (Middleware $middleware) {
// trust all proxy
$middleware->trustProxies(at: '*');
})
2. You need to force all the requests using secured protocol. Open ./app/Providers/AppServiceProvider.php file and enter the following codes.
public function boot(): void
{
// Force HTTPS in production
if ($this->app->environment('production')) {
\Illuminate\Support\Facades\URL::forceScheme('https');
}
}
You may need to re-cache the config file by entering,
php artisan config:cache