Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mauritz-fhd's avatar

Laravel handeling multiple domains behind reverse prxy

I'm trying to set up a server for an application that handles differently depending on the domain the request originated from. So a request from abc.company.com gets different content than xyz.company.com

I'm using docker to containerize the application and apache as an reverse proxy

My apache config looks like this:

and my bootstrap/app.php like this

However if I print the domain with dd(url()->current()); its always returning protocol://localhost:1234

Btw. laracasts prevents me from including links (including localhost so I replaced http with protocol and protocol secure

0 likes
1 reply
mauritz-fhd's avatar

Found my problem. In my bootstrap/app.php I used

        $middleware->trustProxies(at: [
            '127.0.0.1'
        ], headers:
            Request::HEADER_X_FORWARDED_FOR |
            Request::HEADER_X_FORWARDED_HOST |
            Request::HEADER_X_FORWARDED_PORT |
            Request::HEADER_X_FORWARDED_PROTO
        );

the ip should have been the ip of the docker gateway or if you want to keep it simple just 172.17.0.0/16

Please or to participate in this conversation.