Linux – Apache proxy balancer not working properly

apache-2.2linuxmod-proxy

I am having two wildfly server instances up on my linux server and i want to balance load on both by using apache proxy balancer. But the balancer is not working properly its send request to wildfly servers one after another in round robin form but none is working properly. On my website i can see login page but after adding login credentials its not redirecting to the home page and in the logs i can see its logged in properly.
If i stop one server then everything works properly

Here is my proxy configuration

 ProxyRequests Off

ProxyPreserveHost On
ProxyVia On

 <Proxy balancer://mycluster>
                # WebHead
                BalancerMember http://x.y.z.z:8080
                # WebHead2
                BalancerMember http://x.y.z.z:8280 


        </Proxy>

ProxyPass /test balancer://mycluster/test 
ProxyPassReverse /test balancer://mycluster/test 

Please tell me what is wrong in this and how can i correct that

Best Answer

What's probably happening is that you're logging in on Server1 (x.y.z.z:8080), but the next request goes to Server2(x.y.z.z:8280), which has no knowledge of your session on Server1.

There's two major ways to fix this.

  1. Share session state between servers
    The way you do this varies depending on your server-side technology (PHP, Java, Pyton), but basically you'd use a common location (Redis, SQL, MemCached, etc..) to store the session information for both servers, so that any given connection can go to either server and be recognized.

  2. Enable "sticky sessions" in your mod_proxy config
    Again, the actual details of how to do this depend on your server-side technology, but in broad strokes you'd need to add a stickysession key/Value pair to your ProxyPass directive, as outlined in the docs.