0

我在配置 apache 2.4 以使用它的 proxy_balancer mod 时遇到困难。我的用例相当简单。请求正在到达应该负载平衡到集群的 apache 节点。这是我的config

<VirtualHost *:80>

    ProxyRequests off

    ServerName localhost

    <Proxy balancer://geocode>

            BalancerMember "http://192.168.2.11:8080/ors/status"
            BalancerMember "http://192.168.2.35:8080/ors/status"

            Require all granted

            ProxySet lbmethod=byrequests

    </Proxy>

    <Location /balancer-manager>

            SetHandler balancer-manager

            Require all granted

    </Location>

    ProxyPass /balancer-manager !
    ProxyPass "/geocodelb" "balancer://geocode"
    ProxyPass "/geocode" "http://192.168.2.35:8080/ors/status"

</VirtualHost>

当导航到localhost:80/geocodelb我收到404 Not Found

129.206.205.50 - - [01/Oct/2017:19:39:55 +0000] "GET /geocodelb 
HTTP/1.1" 404 164 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; 
rv:56.0) Gecko/20100101 Firefox/56.0"

localhost:80/geocode有效:

129.206.205.50 - - [01/Oct/2017:19:40:07 +0000] "GET /geocode HTTP/1.1" 
200 757 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:56.0) 
Gecko/20100101 Firefox/56.0"

../status指向一个 tomcat 实例并返回一个 json 对象)

如果我用任意的东西替换 BalancerMembers 的 url - 比如google.com- 它可以工作。

我还可以联系平衡器经理localhost:80/balancer-manager并获取正确的信息。如果我没记错的话,它告诉我一切看起来都很好(见截图)。我在这里想念什么?

在此处输入图像描述

4

1 回答 1

1

这不起作用的原因是平衡器成员必须是服务器的 url,没有路径。该路径将被添加到 ProxyPass 指令中,如下所示balancer://orsbackend/ors/geocode。这里的工作配置:

<VirtualHost *:80>

        ProxyRequests off

        ServerName localhost

        <Proxy balancer://orsbackend>
                BalancerMember "http://192.168.2.11:8080"
                BalancerMember "http://192.168.2.35:8080"
                ProxySet lbmethod=byrequests
        </Proxy>

        <Location /balancer-manager>
                SetHandler balancer-manager

                Require all granted
        </Location>

        ProxyPass /balancer-manager !

        ProxyPass "/geocode" "balancer://orsbackend/ors/geocode"

</VirtualHost>
于 2017-10-02T07:42:11.057 回答