【问题标题】:configuring multiple domains using virtual host with mod proxy in a single httpd instance在单个 httpd 实例中使用带有 mod 代理的虚拟主机配置多个域
【发布时间】:2020-08-29 14:15:12
【问题描述】:

我有一个使用基于名称的虚拟主机运行三个域的 apache 实例,每个域都有资源将它们反向代理到应用程序服务器。应用服务器是一个运行自 JVM 实例的 JBoss (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 有两个(根 (/) 和 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】:

    使用以下序列并进行测试。

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

    【讨论】:

    • 谢谢。这行得通。显然这是我在第一步中错过的资源设置为代理的顺序。
    【解决方案2】:

    在 www.ghi.com 创建三个不同的基于名称的虚拟主机并禁用上下文(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>
    

    【讨论】:

    • 嗨,尝试更新配置以通过添加来阻止跨域资源!遵循ProxyPass,但它没有奏效。仍然可以通过 ghi.com 访问 alpha。
    • 分享您的最新配置文件。
    • 用修改后的配置文件更新了问题。请参阅更新 1。
    猜你喜欢
    • 2017-09-25
    • 2015-11-24
    • 2013-04-26
    • 2011-02-22
    • 2016-06-30
    • 2018-04-29
    • 2016-03-31
    • 2017-12-09
    • 1970-01-01
    相关资源
    最近更新 更多