Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have set up Apache and Tomcat on my system and I want to combine both using Mod_JK. I have created a mod_jk worker (ajp13_worker) and added a virtual host to my Apache config:

<VirtualHost *:80>
    ServerName      tomcat.mydomain.com
    DocumentRoot    /usr/local/tomcat/webapps/      

        # Tomcat
    JkMount /* ajp13_worker
    JkMount /*.jsp ajp13_worker
    JkMount /*.jspx ajp13_worker

and it works fine, I end up on the default Tomcat page. The Manager applications are working fine too.

Next, I have my application, which sits in the PATH-TO-TOMCAT/webapps/myapp folder. It should be reachable under myapp.mydomain.com, so I added a second vhost, this time with "DocumentRoot /usr/local/tomcat/webapps/myapp". But it did not work: I always landed on the default Tomact page and not in the root of my app. So I used ModRewite, to rewite the request to the context of my app. The Apache vhost looks like this:

<VirtualHost *:80>
        ServerName      myapp.mydomain.com
        DocumentRoot    /usr/local/tomcat/webapps/myapp/

        RewriteEngine On
        RewriteCond     %{REQUEST_URI}   !^/myapp/.*
        RewriteRule ^/(.*)$ /myapp/$1 [PT]

        # Tomcat
        JkMount /* ajp13_worker
        JkMount /*.jsp ajp13_worker
        JkMount /*.jspx ajp13_worker

That vhost works, the requests are rewritten and my app is reachable under myapp.mydomain.com But now, my Tomcat creates for every single request a new session and the session count explodes when a few users access the page.

I tried several tutorials, but most of them did not address this issue. I think I am missing something. Could someone explain to me how virtual hosts are correctly set up in the combination Apache/Tomcat/Mod-JK?

Thanks a lot,


share|improve this question
What do you intend to do with the virtual host tomcat.yourdomain.com? –  quanta Aug 10 '11 at 3:33
I want to use it to access the default manager apps. they should be available under tomcat.mydomain.com/manager –  Claude Aug 10 '11 at 5:25

1 Answer 1

up vote 0 down vote accepted

Ok, I found it. In the Tomcat sever.xml, you can specify the context path for each host:

<Host name="app.mydomain.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Context path="" docBase="PATH-TO-TOMCAT/webapps/app"/>

My mistake was, that I always tried to modify the appBase parameter and did not know about the Context element!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.