Search code examples
apachevirtualhosthttpd.confmod-proxy

configuring multiple domains using virtual host with mod proxy in a single httpd instance


I have an apache instance running three domains using name based virtual hosting and every domain has resources to reverse proxy them down to an application server. Application server is a JBoss running a since JVM instance (http://x.x.x.x:8080/)

The domains along with their resources are,

www.abc.com
 - alpha
www.def.com
 - beta
www.ghi.com
 - gamma
 - (root URL - no resource)

abd.com and def.com domains have one resource whereas ghi.com has two (root (/) and gamma).

this is how we have setup virtual hosting for three different domains. A sample for abc.com domain is below,

<VirtualHost *>
ServerName abc.com

            Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/alpha" env=BALANCER_ROUTE_CHANGED
            <Proxy balancer://mycluster1>
                        <LimitExcept POST GET>
                                order Allow,Deny
                                Deny from all
                        </LimitExcept>
                                BalancerMember http://x.x.x.x:8080 route=1 retry=0
                                BalancerMember http://x.x.x.x:8081 route=2 retry=0
                                ProxySet stickysession=ROUTEID
            </Proxy>
        ProxyPass /alpha balancer://mycluster4/alpha
        ProxyPassReverse /alpha balancer://mycluster4/alpha
</VirtualHost>

With all configuration in place when I try accessing these domains,

www.abc.com/alpha  --> works
www.def.com/beta   --> works

www.ghi.com/gamma  --> works
www.ghi.com/       --> works

since ghi.com domain has a root mapping (/) I am able to access resources of other domain through ghi.com and if I remove the root mapping, cross domain resource accessibility does not work.

www.ghi.com/alpha   --> works
www.ghi.com/beta    --> works

I do not want the resources of other domain to be accessed through ghi.com. I cannot remove root mapping from ghi.com virtual host configuration.

We have tried multiple configuration but none has worked out. I may sound bit non technical here which I apologize, but this is my problem statement and I am looking for for a fix.


update 1: configuration file after fix proposed by pandurang.

NameVirtualHost *
<VirtualHost *>
ServerName ghi.com

    Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/gamma " env=BALANCER_ROUTE_CHANGED
    Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/ " env=BALANCER_ROUTE_CHANGED
    <Proxy balancer://mycluster4>
                <LimitExcept POST GET>
                        order Allow,Deny
                        Deny from all
                </LimitExcept>
                        BalancerMember http://x.x.x.x:8080 route=1 retry=0
                        BalancerMember http://x.x.x.x:8081 route=2 retry=0
                        ProxySet stickysession=ROUTEID
    </Proxy>
    ProxyPass /gamma balancer://mycluster4/gamma
    ProxyPassReverse /gamma balancer://mycluster4/gamma
    ProxyPass / balancer://mycluster4/
    ProxyPassReverse / balancer://mycluster4/
    ProxyPass /alpha !
</VirtualHost>

Solution

  • Use the below sequence and test.

    ProxyPass /alpha !
    ProxyPass /gamma balancer://mycluster4/gamma
    ProxyPassReverse /gamma balancer://mycluster4/gamma
    ProxyPass / balancer://mycluster4/
    ProxyPassReverse / balancer://mycluster4/