Tomcat – How to configure both apache and tomcat on same url

apache-2.2mod-proxytomcaturl

Say I have a registered URL mywebsite.com pointing to my server with a public IP address.

I want to run both tomcat and apache to serve pages (i.e., some static pages on apache and some dynamic pages on tomcat, like jsp etc…).

For the sake of simplicity, let's assume that apache is listening on 80 and tomcat on 8080.

I heard about mod_proxy. Is it possible to have requests to mywebsite.com go to apache and mywebsite/loggedin go to tomcat? If yes, how should this be configured and where? Thanks.

Best Answer

I would recommend using mod_jk--it tends to be more specific than mod_proxy, and easier to debug. You can forward contexts. I.e., if I have webapp1 and webapp2 running on Tomcat, and I have an images directory on Apache, this would work:

<VirtualHost *:80>
    ...
    JKMount /webapp1/* ajp13
    JKMount /webapp2/* ajp13
    Alias /images "/some/local/dir"
</VirtualHost>

This is also much easier to configure, and most distributions already have packages in their native package managers. Hope this helps!

Related Topic