在一个httpd实例中使用虚拟主机和mod代理配置多个域。

问题描述 投票:0回答:1

我有一个apache实例,使用基于名称的虚拟主机运行三个域名,每个域名都有资源反向代理到应用服务器。应用服务器是一个JBoss,运行一个自JVM实例(http:/x.x.x.x:8080。)

这些领域及其资源是:

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

abd.com和def.com域名有一个资源,而ghi.com有两个资源(root()和gamma)。

这就是我们如何为三个不同的域名设置虚拟主机。下面是abc.com域名的例子。

<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>

在所有配置到位的情况下,当我尝试访问这些域时。

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

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

由于ghi.com域名有一个根映射(),我可以通过ghi.com访问其他域名的资源,如果我把根映射删除,跨域资源访问就无法进行。

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

我不希望通过ghi.com访问其他域的资源。我无法从ghi.com虚拟主机配置中移除根映射。

我们已经尝试了多种配置,但都没有成功。我可能听起来有点非技术性,我很抱歉,但这是我的问题陈述,我正在寻找修复方法。


更新1: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>
apache virtualhost httpd.conf mod-proxy
1个回答
2
投票

使用下面的顺序和测试。

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

0
投票

在www.ghi.com,创建三个不同的基于名称的VirtualHost,并禁用上下文(alpha和beta)。

<VirtualHost www.abc.com>
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>

<VirtualHost www.def.com>
ServerName def.com
Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/beta" 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 /beta balancer://mycluster4/beta
ProxyPassReverse /beta balancer://mycluster4/beta
</VirtualHost>

<VirtualHost www.ghi.com>
ServerName ghi.com
Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" 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 !
ProxyPass /beta !
ProxyPass / balancer://mycluster4/
ProxyPassReverse / balancer://mycluster4/
</VirtualHost>
© www.soinside.com 2019 - 2024. All rights reserved.