3

Okay, so I've been working for a while on this, and have been searching, but so far I have not found any answers that actually answer what I want to know. I'm a little bit at the end of my rope with this one, but I'm hoping I can figure this out sometime soon.

So I have Apache 2 installed and serving up standard webpages, but I also have that linked to a Tomcat instance for one of my domains currently supported. However, I want to add another domain to the server via Apache that points to a separate code base from the one I already have. I have been coming at this from several different angles, and I have determined that I just don't know enough about setting up these servers to really do what I want to do.

Little information on my server: Currently running a single Tomcat5.5 instance with Apache 2, using mod_jk to connect them together.

I have a worker in workers.properties that points it's "host" field to "localhost" with the correct port my Tomcat instance, so that all works.

In my Tomcat server.xml file, I have a host defined as "localhost" that points at my webapp that I am currently serving up, with that host set as the defaultHost as well.

One thought I had was that I could add a new worker with a different host than "localhost" (i.e. host2) and then define a new host in my server.xml file called "host2" to match it, but after reading around some on the internet, It seems the "host" of the worker must point to a server, and not a hostname in the Tomcat instance, is this correct?

Again, a simple rundown of what I want: Setup in apache/tomcat combo such that www.domain1.com points at "webapp1" and www.domain2.com points at "webapp2".

Royce Thigpen
  • 31
  • 1
  • 2
  • Ideas off the top of my head: use mod_proxy instead of mod_jk, set up virtual servers in your Apache configuration and either proxy to a different Tomcat instance, or use mod_rewrite/mod_proxy to proxy the request to a different URL on the Tomcat server. – PP. Nov 19 '09 at 18:32
  • 1
    About mod_proxy, the Tomcat Connectors FAQ (http://wiki.apache.org/tomcat/FAQ/Connectors) writes: **mod_jk [...] should be used for production.** mod_proxy. A cheap way to proxy without the hassles of configuring JK. This solution lacks sticky session load balancing. If you don't need some of the features of jk - this is a very simple alternative. – Pascal Thivent Nov 19 '09 at 21:16
  • mod_proxy_balancer supports stick session load balancing, I know because I've seen it configured and working in our organisation last week. Note that a `jvmroute` must be set for each Tomcat instance. (See http://www.wellho.net/archives/2009/10/load_balancing_2.html) – PP. Nov 20 '09 at 10:01

2 Answers2

10

First, setup mod_jk workers for both webapps. Below a sample workers.properties:

workers.tomcat_home=/usr/local/tomcat/apache-tomcat-6.0.20
workers.java_home=/usr/lib/jvm/java-6-sun
ps=/
worker.list=worker1,worker2
worker.worker1.type=ajp13
worker.worker1.host=www.domain1.com
worker.worker1.port=8009
worker.worker2.type=ajp13
worker.worker2.host=www.domain2.com
worker.worker2.port=8009

Then, set up virtual hosts on apache:

<VirtualHost *:80>
   ServerName www.domain1.com
   JkMount /* worker1
</VirtualHost>

<VirtualHost *:80>
   ServerName www.domain2.com
   JkMount /* worker2
</VirtualHost>

Make sure the server.xml contains an uncommented AJP Connector for port 8009 (matching the workers port). Like this :

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

Finally, configure the tomcat hosts. Something like this:

<Host name="www.domain1.com"
   appBase="/path/to/domain1"
   unpackWARs="true"
   autoDeploy="true"
   xmlValidation="false"
   xmlNamespaceAware="false">

<Host name="www.domain2.com"
   appBase="/path/to/domain2"
   unpackWARs="true"
   autoDeploy="true"
   xmlValidation="false"
   xmlNamespaceAware="false">

You might need to make some adaptation but it should be close to the final result.

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
0

You could also use much simpler approach with mod_proxy. Have a look at http://squirrel.pl/blog/2010/03/30/mapping-tomcat-apps-to-subdomains-with-apache/

Konrad Garus
  • 53,145
  • 43
  • 157
  • 230