0

Well, I have setup an LB with apache2, behind it, there a project (ZF2 PHP), that is an Ecommerce.

I intend to have many DNS's from clients, and all of them pointing to my LB, and dispatching this requests, but my problem, is between LB and slaves servers, there's a way to me identity from which DNS, that request is?

Today I have this

<VirtualHost *:80>
    ServerName client1.com
    ServerAlias www.client1.com

    ProxyRequests Off
    <Proxy \*>
        Order deny,allow
        Deny from all
    </Proxy>

    <Proxy balancer://clusterA>
    BalancerMember http://http1.mysubdomain.com/10
    BalancerMember http://http2.mysubdomain.com/10
    Order allow,deny
    Allow from all
    </Proxy>
    ProxyPass / balancer://clusterA/
</VirtualHost>

<VirtualHost *:80>
    ServerName client2.com
    ServerAlias www.client2.com

    ProxyRequests Off
    <Proxy \*>
        Order deny,allow
        Deny from all
    </Proxy>

    <Proxy balancer://clusterB>
    BalancerMember http://http1.mysubdomain.com/20
    BalancerMember http://http2.mysubdomain.com/20
    Order allow,deny
    Allow from all
    </Proxy>
    ProxyPass / balancer://clusterB/
</VirtualHost>

This way, if access website from client 1 (client1.com), my project will know that he's ID is 10, and if it's from (client2.com) will be 20.

And that kinda works, but I'm having a hard time to control routes and paths (including 'public/' content inside the project.

Any tips/ideas? Thanks

2 Answers2

0

You need to use PHP's $_SERVER['SERVER_NAME'] variable for checking which virtual host the request was sent to.

Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63
  • Almost this, but 'X-Forwarded-Server' is not present in $_SERVER, and $_SERVER['SERVER_NAME'] return the name of the machine, not the source DNS, anyway, ty – Fernando Fernandes May 04 '18 at 12:48
0

Well, happens that I just need look at my headers, when I access through the LB, there's a change on the headers, which come with X-Forwarded-Server that indicate from which DNS came from. In this case, I use the method getallheaders() from PHP.