简体   繁体   中英

Apache load balancing with proxy_balancer

I am having difficulties configuring apache 2.4 to use it's proxy_balancer mod. My use case is fairly straight forward. Requests are reaching the apache node which should be load balanced to the cluster. This is my 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>

When navigating to localhost:80/geocodelb I receive 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"

but localhost:80/geocode works:

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"

(The ../status points to a tomcat instance and returns a json object)

If I replace the url's of the BalancerMembers with something arbitrary - like google.com - it works.

I can also reach the balancer-manager at localhost:80/balancer-manager and obtain the correct information. If I am not mistaken it is telling me that everything looks ok (see screenshot). What am I missing here?

在此处输入图片说明

The reason for this not working is that the balancermember must be a url to a server, without a path. The path is to be added in the ProxyPass directive, like this balancer://orsbackend/ors/geocode . Here the working config:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM