mod_proxy: sticky session does not work - apache

I have two JBoss AS 7 servers and I'm doing load balancing using mod_proxy. Almost everything works fine besides sticky sessions. I have session id in a cookie not in the URL as JSESSIONID.
Here is my apache configuration:
NameVirtualHost *:80
<VirtualHost *:80>
ProxyPass / balancer://mycluster/ stickysession=JSESSIONID|jsessionid nofailover=Off
ProxyPassReverse / balancer://tutcluster/
ProxyPassReverse / http://server1:8080/
ProxyPassReverse / http://server2:8080/
ProxyPreserveHost On
ProxyRequests Off
<Location / >
Order deny,allow
Allow from All
</Location>
<Proxy balancer://mycluster/>
BalancerMember http://server1:8080 route=jbossWeb1 retry=60
BalancerMember http://server2:8080 route=jbossWeb2 retry=60
</Proxy>
</VirtualHost>

OK, I've found it. There were two problems Firstly I forgot to set jvmRoute property in the JBoss configuration. So I set:
<system-properties>
<property name="jvmRoute" value="nodeX"/>
</system-properties>
and changed workers configuration to:
BalancerMember http://server1:8080 route=nodeX retry=60
The second problem was nofailover=Off. It probably caused that some parts of the static content was loaded from one server and some parts of it -- from another one.

Related

Apache 2.4 - configure ProxyPass based on full url instead of trailing path

Currently I have the following ProxyPass's configured in my Apache httpd.conf file.
The goal is to have one Proxypass on http://myurl.com:port1/mypath to one balance group, and then have any additional Proxypass go to http://myurl.com:port2/mypath to any additional balance groups.
Here is my code currently as is which only works based on the /mypath apparently and can have no proceeding URL. The problem is my two /mypath's are the same and only differ by port1 and port2 in the URL.
I am currently listening on Port1 and Port2 defined above in Apache, but I have no way currently to distinguish if someone who comes in on myurl.com:port1 will get directed to Group1 or Group2 in the balance manager because the /mypath is the same for both.
<IfModule proxy_module>
ProxyPass /mypath balancer://Group1/ stickysession=JSESSIONID|jsessionid
ProxyPass /mypath balancer://Group2/ stickysession=JSESSIONID|jsessionid
<Proxy balancer://Group1>
BalancerMember ajp://myurl.com:portX/mypath route=TC01
</Proxy>
<Proxy balancer://Group2>
BalancerMember ajp://myurl.com:portY/mypath route=TC01
</Proxy>
</IfModule>
The below does not work but this is essentially what I am trying to do:
<IfModule proxy_module>
ProxyPass http://myurl.com:port1/mypath balancer://Group1/ stickysession=JSESSIONID|jsessionid
ProxyPass http://myurl.com:port2/mypath balancer://Group2/ stickysession=JSESSIONID|jsessionid
<Proxy balancer://Group1>
BalancerMember ajp://myurl.com:portX/mypath route=TC01
</Proxy>
<Proxy balancer://Group2>
BalancerMember ajp://myurl.com:portY/mypath route=TC01
</Proxy>
</IfModule>
Since ProxyPass cannot occur within <If> section, seems like you are left with splitting your configuration in two VirtualHosts:
<VirtualHost *:port1>
ServerName myurl.com
<Proxy balancer://Group1>
BalancerMember ajp://myurl.com:portX/mypath route=TC01
</Proxy>
ProxyPass /mypath balancer://Group1/ stickysession=JSESSIONID|jsessionid
</VirtualHost>
<VirtualHost *:port2>
ServerName myurl.com
<Proxy balancer://Group2>
BalancerMember ajp://myurl.com:portY/mypath route=TC01
</Proxy>
ProxyPass /mypath balancer://Group2/ stickysession=JSESSIONID|jsessionid
</VirtualHost>

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>

Map apache2 proxy to different ports

I am running apache 2.2 and have a problem to map two different applications (Plex and Owncloud) on port 80. What I want to do is to proxy example/plex to localhost:32400/web (which is the default setting of plex). Also I want to map example/cloud on localhost/owncloud.
What I have tried so far:
<VirtualHost *:80>
ServerName example
<Proxy *>
Order deny,allow
Allow from 192.168.1.0/24
</Proxy>
ProxyPreserveHost On
ProxyRequests Off
ProxyPass /cloud http://127.0.0.1/owncloud/
ProxyPassReverse /cloud http://127.0.0.1/owncloud/
<Location /plex/>
ProxyPass http://127.0.0.1:32400/web/
ProxyPassReverse http://127.0.0.1:32400/web/
</Location>
</VirtualHost>
That works for the cloud => owncloud proxy, but for some reason, whatever I try it doesn´t work for the Plex with port 32400.
I also tried with this instead of the Location block:
ProxyPass /plex http://127.0.0.1:32400/web/
ProxyPassReverse /plex http://127.0.0.1:32400/web/
Thanks in advance!

Configuring Apache Load Balancer

I have the following code added to my httpd.conf to load balance between two Application Servers
<VirtualHost www.mydomainx.com:80>
ProxyRequests off
ProxyPreserveHost Off
ServerName www.mydomainx.com
ServerAlias mydomainx.com
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /test balancer://mycluster stickysession=JSESSIONID|jsessionid
<Proxy balancer://mycluster>
# WebHead1
BalancerMember http://www1.mydomainx.com
# WebHead2
BalancerMember http://www2.mydomainx.com
Order Deny,Allow
Deny from none
Allow from all
ProxySet lbmethod=byrequests
</Proxy>
<Location /balancer-manager>
SetHandler balancer-manager
# I recommend locking this one down to your
# your office
Order deny,allow
Allow from all
</Location>
ProxyPass /balancer-manager !
ProxyPass / balancer://mycluster/
</VirtualHost>
Whenever i enter the URL to a web browser www.mydomainx.com, it loads the home page , then if i enter a user name and password and click submit, it then reloads either (http://www1.mydomainx.com / http://www2.mydomainx.com) reloading the home page again and forcing me to re-enter the username and password, is there a way to prevent all this?
Make sure you follow the advice in section stickyness:
ProxyPass / balancer://mycluster stickysession=JSESSIONID|jsessionid scolonpathdelim=On
(not only for the /test directory)
Furthermore, for the JBoss application server, you need to supply route=web1 / route=web2 etc. in the Apache config and furthermore jvmRoute="web1" in the JBoss configuration of the <Engine name="jboss.web"... element (the location depends on the JBoss version you are using, for v4.2 it is server/default/deploy/jboss-web.deployer/server.xml)
See also this tutorial

How to forward only *.jsp or *.do requests to Tomcat using mod_proxy?

I am using mod_proxy module to forward all requests for one of my domain to be served by Tomcat. However I want to forward only requests ending *.jsp or *.do or *.something to Tomcat and rest (e.g. *.html, *.php, *.png) to be served by Apache server. How to achieve that using mod_proxy?
Following is sample httpd.conf config that I am using currently:
<VirtualHost *:80>
DocumentRoot /usr/share/tomcat6/webapps/mywebapp
ServerName example.com
ServerAlias www.example.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
</VirtualHost>
I know that you had found the answer but I write this answer for others that maybe need it:
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
#ProxyPass / ajp://localhost:8009/
ProxyPassMatch ^/(.*\.do)$ ajp://localhost:8009/$1
ProxyPassMatch ^/(.*\.jsp)$ ajp://localhost:8009/$1