mod_proxy isn't using the port defined in my balancermembers - apache

I'm trying to set up my apache load balancer to proxy to the same backend clusters to apps running on different ports. The cluster definitions are like this:
<Proxy balancer://wordpress-cluster>
BalancerMember http://192.168.2.10:80
BalancerMember http://192.168.2.11:80
</Proxy>
<Proxy balancer://corporate-cluster>
BalancerMember http://192.168.2.10:81
BalancerMember http://192.168.2.11:81
</Proxy>
In the load balancer, one of the vhost needs to talk to both, so in the vhost definition I have:
ProxyRequests Off
ProxyPreserveHost Off
SSLProxyEngine On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /feed balancer://wordpress-cluster/feed lbmethod=byrequests
ProxyPassReverse /feed balancer://wordpress-cluster/feed
ProxyPass / balancer://corporate-cluster/ lbmethod=byrequests
ProxyPassReverse / balancer://corporate-cluster/
when requesting for '/' , I get the content served from the port 80 app, not the port 81 app.
Would anyone know on what is happening? it looks like this might be a case of overzealous worker sharing, but shouldn't specifying the different ports prevent that?
Is there something else I should do?
Forgot to mention: this is using apache 2.2.4-1 on a centos box.
Thanks in advance!
Tim

OK, so I still don't know what happened. Did 2 steps to fix my problem:
1) split the cluster into 2 1-machine clusters and things worked:
<Proxy balancer://wordpress-cluster>
BalancerMember http://192.168.2.10:80
</Proxy>
<Proxy balancer://corporate-cluster>
BalancerMember http://192.168.2.11:81
</Proxy>
But of course that killed balancing and failover support... not good
Second option, create dns aliases to ensure that the balancermembers looked different (even though they point to the same boxes:
<Proxy balancer://wordpress-cluster>
BalancerMember http://192.168.2.10:80
BalancerMember http://192.168.2.11:80
</Proxy>
<Proxy balancer://corporate-cluster>
BalancerMember http://corp01:81
BalancerMember http://corp02:81
</Proxy>
And voila! The setup is now working for me :)

Related

Apache load balancer just uses first entry

I have configured a loadbalancer for Apache as following:
<Proxy "balancer://mycluster">
BalancerMember "http://127.0.0.1:8081/" loadfactor=1
BalancerMember "http://127.0.0.1:8082/" loadfactor=1
ProxySet lbmethod=byrequests
</Proxy>
<VirtualHost *:80>
ServerName subdomain.example.com
ProxyPass / "balancer://mycluster"
ProxyPassReverse / "balancer://mycluster"
</VirtualHost>
If i fire some requests at it like in
for i in `seq 1 100`
curl http://subdomain.example.com/ping &
I get my pong (which is the balancers response) 100 times
But the logs are only showing the requests in my first BalancerMember at port 8081.
How can I debug this or change to a round-robin style?

how to config apache point to another index in different server?

I am configuring 3 tiers setup(webserver, database server, and application server). I want to separate everything into 3 three servers. I have already separated between the application server and the database server. Regarding to webserver and application server, I don't know how to config apache to point to my application server. I tried to share file and folder from application server to webserver already with samba share, but it still did not work. The problem is apache server can access the resource in the other server(application server).
If you everyone used to solved or faced this problem. Could you please help me?
Thank in advance.
As a part of an old assignment I had achieved something similar using below config.
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
<Proxy "balancer://mycluster">
BalancerMember "http://10.0.0.1:8001"
BalancerMember "http://10.0.0.1:8002"
BalancerMember "http://10.0.0.1:8003"
BalancerMember "http://10.0.0.1:8004"
BalancerMember "http://10.0.0.1:8005"
BalancerMember "http://10.0.0.1:8006"
ProxySet lbmethod=byrequests
</Proxy>
ProxyPass / "balancer://mycluster/" stickysession=BALANCEID
ProxyPassReverse / "balancer://mycluster/"
</VirtualHost>
For your case, I feel changing your Virtual Host as below must do the magic.
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
<Proxy "balancer://mycluster">
BalancerMember "http://192.168.2.35:8000"
ProxySet lbmethod=byrequests
</Proxy>
ProxyPass / "balancer://mycluster/" stickysession=BALANCEID
ProxyPassReverse / "balancer://mycluster/"
</VirtualHost>
Also ensure that you enable the lbmethod_byrequests_module in your apache.
You just need a basic reverse proxy configuration. The absolute basics are loading mod_proxy, mod_proxy_http, and using ProxyPass to match the URL's you want to pass to the backend system.

Load balancer with apache httpd and wildfly for rest web services with mod_proxy

I have an apache load balancer with mod_proxy and wildfly (apache 224 and wildfly 9).
I have 4 servers in domain in wildfly and the load balancer works fine with a "hello world" app, and in the balancer manager i can see how the requests are sent to each server.
The thing is, When I use the app that has some REST web services, i am sending the request with a GET method and some headers for authentication, and somehow, the application is responding with error when i access it through the load balancer, but if I send it directly to the server, it works correctly.
my cofiguration goes as follows
<VirtualHost *:80>
ProxyRequests Off
<Proxy balancer://mycluster>
BalancerMember http://localhost:8080/ loadfactor=25
BalancerMember http://localhost:8230/ loadfactor=25
BalancerMember http://localhost:8330/ loadfactor=25
BalancerMember http://localhost:8430/ loadfactor=25
</Proxy>
<Location /balancer-manager>
SetHandler balancer-manager
Order Deny,Allow
Allow from all
</Location>
<Location /test>
Order allow,deny
Allow from all
</Location>
ProxyPass /test balancer://mycluster stickysession=JSESSIONID
I am testing using postman and sending the requests with a get method and a header for authentication: basic {base64 code} as follows:
http://127.0.0.1/test/myproject.ws/myproject/get_list?key=T11108101191&page=1
and this results in error.
when i try this:
http://127.0.0.1:8080/myproject.ws/myproject/get_list?key=T11108101191&page=1
This goes ok
and when i try the above, but with a post method, it gets the same error as in the load balancer.
Any idea of what am i doing wrong?
PS: I've tried putting in the WEB-INF/web.xml of the project, but i still get the same error.
Thanks to Dusan Bajic, he saw the problem I had. In the balancer member i was finishing the route with "/" and when I used the ProxyPass, i was starting with "/", duplicating that character. Somehow, with the helloworld app it worked correctly, but when i pass parameters, it failed.
The new configuration goes as follows:
<VirtualHost *:80>
ProxyRequests Off
<Proxy balancer://mycluster>
BalancerMember http://localhost:8080 loadfactor=25
BalancerMember http://localhost:8230 loadfactor=25
BalancerMember http://localhost:8330 loadfactor=25
BalancerMember http://localhost:8430 loadfactor=25
</Proxy>
<Location /balancer-manager>
SetHandler balancer-manager
Order Deny,Allow
Allow from all
</Location>
<Location /test>
Order allow,deny
Allow from all
</Location>
ProxyPass /test balancer://mycluster stickysession=JSESSIONID
</VirtualHost>

Apache 2.2 mod_proxy failover/load balancing

I am using mod_proxy_balancer to manage failover of backend servers (tcServers). Backend servers may return an error code instead of timing out when some other backend service fails such as NFS and we want such servers also to be marked as failed nodes. Hence we are using failonstatus directive.
<Proxy balancer://awstestbalancer>
ProxySet failonstatus=503
BalancerMember https://host:port/context/ retry=30
# the hot standby
BalancerMember https://host:port/context/ status=+H retry=0
</Proxy>
ProxyPass /context balancer://awstestbalancer
ProxyPassReverse /context balancer://awstestbalancer
Currently the failover works perfectly with one glitch. When active node fails the user gets a 503 error and from the next request the Standby server takes over.
I dont want even a single request to fail though. Cant mod_proxy failover with out ever returning an error to the client? If active node fails I want mod_proxy to try the Standby for the same request and not just from the subsequent request!
I have also tried the following settings, but they did not work. Using APACHE 2.2.59
<Proxy balancer://awstestbalancer>
BalancerMember https://host:port/context route=tcserver1 loadfactor=1
BalancerMember https://host:port/context route=tcserver2 loadfactor=1
ProxySet lbmethod=bybusyness
ProxySet nofailover=Off
ProxySet stickysession=JSESSIONID
</Proxy>
ProxyPass /context balancer://awstestbalancer
ProxyPassReverse /context balancer://awstestbalancer
AND
<Proxy balancer://awstestbalancer>
BalancerMember https://host:port/context route=tcserver1 loadfactor=1 ping=5
BalancerMember https://host:port/context route=tcserver2 loadfactor=1 ping=5
ProxySet lbmethod=bytraffic
ProxySet nofailover=On
ProxySet stickysession=JSESSIONID
</Proxy>
ProxyPass /context balancer://awstestbalancer
ProxyPassReverse /context balancer://awstestbalancer
Thanks!!!
Sid
Following configuration would work. if backend is on AWS and its status changes frequently you could try to decrease the connectiontimeout.
<Proxy balancer://awstestbalancer>
BalancerMember https://host:port/context/ connectiontimeout=5
BalancerMember https://host:port/context/ connectiontimeout=5
</Proxy>
ProxyPass /context balancer://awstestbalancer failonstatus=500,501,502,503,504
ProxyPassReverse /context balancer://awstestbalancer

Load Balancer with Apache HTTPD

I'm struggling to set up a an Apache httpd load balancer in front of a couple of application servers. This is my configuration:
ProxyRequests off
<Proxy balancer://mycluster>
BalancerMember http://127.0.0.1:8080
BalancerMember http://remote-svr:8080
ProxySet lbmethod=bybusyness
ProxySet stickysession=JESSIONIDSSO
</Proxy>
<Location /balancer-manager>
SetHandler balancer-manager
</Location>
ProxyPass /balancer-manager !
ProxyPass / balancer://mycluster/
ProxyPassReverse / balancer://mycluster/
ProxyPassReverseCookieDomain http://127.0.0.1:8080 localhost
ProxyPassReverseCookieDomain http://remote-svr:8080 localhost
I'm not sure the last 2 lines do anything, although one of the many examples I've looked at online used them, so I added them to see if it fixed my problem (it didn't).
The issue is that if I comment out either of the BalancerMember lines eg:
#BalancerMember http://127.0.0.1:8080
BalancerMember http://remote-svr:8080
Then the behaviour from a user perspective is fine, however when both members are active, the behaviour is wrong.
The application initially displays a login screen, however when both load balancers are active, the user on submitting their username and password just get redirected back to the login screen again, maybe the session is being lost somewhere. Does anyone have any idea what the issue might be?
EDIT - NOW WORKING
for reference, this setup now seems to work:
ProxyRequests off
Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
<Proxy balancer://mycluster>
BalancerMember http://127.0.0.1:8080 route=localServer
BalancerMember http://remote-svr:8080 route=remoteServer
ProxySet lbmethod=bybusyness
ProxySet stickysession=ROUTEID
</Proxy>
<Location /balancer-manager>
SetHandler balancer-manager
</Location>
ProxyPass /balancer-manager !
ProxyPass / balancer://mycluster/
ProxyPassReverse / balancer://mycluster/
Note the 'route' attribute for the individual nodes needs to be set on the nodes themselves (server.xml in this case, as the servers run JBoss). JSESSIONID worked ok as the sticky session cookie for individual applications but there is more than one application on each server, and the user needs to use the same node for all.
If I were to guess you probably loose the session due to a typo in this section:
<Proxy balancer://mycluster>
BalancerMember http://127.0.0.1:8080
BalancerMember http://remote-svr:8080
ProxySet lbmethod=bybusyness
ProxySet stickysession=JESSIONIDSSO
</Proxy>
ProxySet stickysession=JESSIONIDSSO this should probably say ProxySet stickysession=JSESSIONIDSSO? Or maybe even JSESSIONID?