lperry65
1 month ago
537
7
Laravel

Load Balancers

Posted 1 month ago by lperry65

I have a Laravel 7 APP with two instances behind an NGINX load balancer, I've set up Trusted Proxies as described in the Laravel docs but I don't think it's working . As soon as I click the login link the page appears but without any styling and there are also two network requests, one for http and a second for https which is from my redirect in the nginx conf. My understanding from the docs is that the Trusted Proxies middleware should take care of this !

A second issue I have is that although I have both Laravel instances using the same Redis server for session and cache, any Socialite login fails with an invalid state error and I'm not sure if this is related to trusted Proxies not working ?

Here is my trusted Proxies file

class TrustProxies extends Middleware
{
    /**
     * The trusted proxies for this application.
     *
     * @var string|array
     */
    protected $proxies = [
        'x.x.x.x'
    ];

    /**
     * The headers that should be used to detect proxies.
     *
     * @var string
     */
    protected $headers = Request::HEADER_X_FORWARDED_ALL;
}

I've tested the Load balancer IP address and its accessible from both Laravel servers, and it's what I'm using in the protected $proxies array.

I don't have any of these issues if I just use one of the Laravel instances without the load balancer.

I've spent a couple of days on google trying to figure this out so any help much appreciated :)

Lee.

Please sign in or create an account to participate in this conversation.