title: Apache 2.2 Virtual hosts + Tomcat 7 applications
body: <p>I have installed on the same machine one <strong>apache server</strong> and one <strong>tomcat 7</strong> server.
  The apache server is used and configured with virtual hosts enabled as is supposed to server multiple php websites.
  However, we have the need to serve some tomcat applications as well so we need to configure the ajp connector.</p>
  
  <p>Everything goes well, I have succeeded in configuring multiple apache virtual hosts which serves tomcat apps but I have only one problem:</p>
  
  <p><strong>The session variables are not be maintained when accessing the java application through the apache virtual host</strong>. This works perfectly well when connecting directly to the 8080 port of the tomcat server.</p>
  
  <p>I can see in the tomcat manager for each application the number of sessions is incremented with every refresh of a page from the apache virtual hosts.</p>
  
  <p>The java application is deployed in tomcat in the /webapps/testapp folder.</p>
  
  <p>The tomcat server xml has a ajp connector described as:</p>
  
  <pre><code>&lt;Connector port="8009" protocol="AJP/1.3" redirectPort="8443" 
  maxThreads="300" minSpareThreads="10" enableLookups="false"
  tcpNoDelay="true" tomcatAuthentication="false" URIEncoding="UTF-8" /&gt;
  </code></pre>
  
  <p>The apache webserver contains the virtual host:</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
      ServerName testapp.com
      ServerAlias *.testapp.com
      ProxyPreserveHost on
      ProxyRequests     off
      ProxyPass / ajp://localhost:8009/testapp/
      ProxyPassReverse / ajp://localhost:8009/testapp/
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>So Apache proxy with tomcat is working fine. The thing is that jsp sessions are not working through the proxy. How can I make it work? Is it something wrong with my config?</p>