English 中文(简体)
Linking Apache to Tomcat with multiple domains
原标题:

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".

问题回答

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.

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/





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签