title: Sticky session not working with multiple apache vhosts and multiple JBoss 7.2 server-groups
body: <p>Having a specific cluster architecture with the following details:</p>
  
  <ul>
  <li>Load balancer (<strong>10.10.0.1</strong>) using Apache's mod_cluster 1.2.0 without advertising using multicast</li>
  <li>2 JBoss AS 7.2 servers (<strong>jboss-instance-1, jboss-instance-1</strong>) in domain mode (host and slave), i'm using proxy-list instead of multicast</li>
  </ul>
  
  <p>In domain.xml i have the following settings (only important snippets):</p>
  
  <pre><code>    ...
          &lt;subsystem xmlns="urn:jboss:domain:modcluster:1.1"&gt;
              &lt;mod-cluster-config advertise-socket="modcluster" connector="ajp" balancer="${mycluster.modcluster.balancer:DefaultBalancer}" proxy-list="10.10.0.1:6677"&gt;
                  &lt;dynamic-load-provider&gt;
                      &lt;load-metric type="busyness"/&gt;
                  &lt;/dynamic-load-provider&gt;
              &lt;/mod-cluster-config&gt;
          &lt;/subsystem&gt;
      ...
      ...
      &lt;server-group name="SG1" profile="ha"&gt;
          &lt;system-properties&gt;
              &lt;property name="mycluster.modcluster.balancer" value="SG1Balancer"/&gt;
          &lt;/system-properties&gt;
          &lt;jvm name="default"/&gt;
          &lt;socket-binding-group ref="ha-sockets"/&gt;
      &lt;/server-group&gt;
      &lt;server-group name="SG2" profile="ha"&gt;
          &lt;system-properties&gt;
              &lt;property name="mycluster.modcluster.balancer" value="SG2Balancer"/&gt;
          &lt;/system-properties&gt;
          &lt;jvm name="default"/&gt;
          &lt;socket-binding-group ref="ha-sockets"/&gt;
      &lt;/server-group&gt;
      ....
  </code></pre>
  
  <p>And in host.xml (same as in slave and host):</p>
  
  <pre><code>    ....
      &lt;servers&gt;
          &lt;server name="server-1" group="SG1" auto-start="true"&gt;
              &lt;socket-bindings port-offset="1"/&gt;
          &lt;/server&gt;
          &lt;server name="server-2" group="SG2" auto-start="true"&gt;
              &lt;socket-bindings port-offset="2"/&gt;
          &lt;/server&gt;
      ....
  </code></pre>
  
  <p>I need to point each virtual hosts to a specific server-group, so this is my solution for it:</p>
  
  <ul>
  <li>www.vhost1.com -> SG1Balancer, which is attached to group=SG1, so it will load balance between:
  <ul>
  <li>jboss-instance-1's server-1</li>
  <li>jboss-instance-2's server-1</li>
  </ul></li>
  <li>www.vhost2.com -> SG2Balancer, which is attached to group=SG2, so it will load balance between:
  <ul>
  <li>jboss-instance-1's server-2</li>
  <li>jboss-instance-2's server-2</li>
  </ul></li>
  </ul>
  
  <p>Here's my httpd configuration sets:</p>
  
  <p>loadbalancer.conf:</p>
  
  <pre><code>LoadModule proxy_module modules/mod_proxy.so
  LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
  
  LoadModule slotmem_module modules/mod_slotmem.so
  LoadModule manager_module modules/mod_manager.so
  LoadModule proxy_cluster_module modules/mod_proxy_cluster.so
  LoadModule advertise_module modules/mod_advertise.so
  
  &lt;IfModule manager_module&gt;
    Listen 0.0.0.0:6677
    ManagerBalancerName ddrct-cluster
  
    &lt;VirtualHost *:6677&gt;
      ServerName RecetteDtvLb1
      &lt;Location /&gt;
        Order deny,allow
        Allow from 0.0.0.0
      &lt;/Location&gt;
  
      # No server advertising
      # we're using proxy-list
      ServerAdvertise Off
  
      KeepAliveTimeout 300
      MaxKeepAliveRequests 0
      EnableMCPMReceive
  
      &lt;Location /mcm&gt;
        SetHandler mod_cluster-manager
        Order deny,allow
        Allow from 0.0.0.0
      &lt;/Location&gt;
    &lt;/VirtualHost&gt;
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>vhosts.conf:</p>
  
  <pre><code>ProxyRequests Off
  NameVirtualHost *:80
  
  &lt;VirtualHost *:80&gt;
    ServerName www.vhost1.com
  
    ProxyPass / balancer://SG1Balancer stickysession=JSESSIONID
    ProxyPassReverse / balancer://SG1Balancer
    ProxyPreserveHost On
  
    ErrorLog "logs/vhost1_error.log"
    CustomLog "logs/vhost1_access.log" common
  &lt;/VirtualHost&gt;
  
  &lt;VirtualHost *:80&gt;
    ServerName www.vhost2.com
  
    ProxyPass / balancer://SG2Balancer stickysession=JSESSIONID
    ProxyPassReverse / balancer://SG2Balancer
    ProxyPreserveHost On
  
    ErrorLog "logs/vhost2_error.log"
    CustomLog "logs/vhost2_access.log" common
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>Everything is running fine, deployed apps in <strong>G1</strong> can be used through <strong>www.vhost1.com</strong> and vice versa for <strong>G2</strong>, the problem is all about session stickyness, here are the symptoms:</p>
  
  <ul>
  <li>My browser is accepting JSESSIONID cookie, but having a content like this: <strong>KhH7gInyAFPsILN6mYDQ84Kf.jboss-instance-1:server-1</strong> will not get my next request sticked to jboss-instance-1's server-1, the load balancer will switch my requests between jboss-instance-1's server-1 and jboss-instance-2's server-1 and each time it changes the JSESSIONID cookie content.</li>
  <li>When i manually edit the content of JSESSIONID cookie (using firecookie plugin) to remove the server name like this: <strong>KhH7gInyAFPsILN6mYDQ84Kf.jboss-instance-1</strong>, my requests will be sticking on jboss-instance-1, leading to a correct behaviour</li>
  </ul>
  
  <p>Did not get too much documentation about multi-vhost and multi-server-group clustering and load balancing configurations, it was my own guess to implement such configuration, i may get it wrong ... any help ?</p>