There are three different way to connect Tomcat and Apache:
1. JK is a project covering web-servers to Tomcat connectors, whereas mod_jk is the Apache module developed in JK.
IIS webserversupport is implemented on JK, using a redirector called isapi redirector.
Netscape/SunONE/Sun webserverwebserver support is implemented on JK, using a redirector called nsapi redirector.
2. http_proxy is a http proxy using HTTP protocol. It work both with Apache 1 and 2. It is very easy configure than JK, but lost some performance.
3. ajp_proxy comes with Apache 2.2.x, it's works with AJP protocol 1.3. So it gets the same performance as JK(even better) and the same easy configuration as http_proxy.
If you are using IIS, JK is the only solution. But if you are using Apache 2.2.x, ajp_proxy is the best solution. Now let's go with it. Since Tomcat 3.x, 4.x, 5.x and 6.x all support AJP 1.3, ajp_proxy can work well with them.
By default, ajp_proxy comes with Apache 2.2.x, to verify that, please check that there is a “proxy_ajp.conf” in “/etc/httpd/conf.d” folder (this is based on Redhat Linux, for some other linux system such as debain, “proxy_ajp.conf” is in “/etc/apache2/mods-available”).
And make sure there is such a line as below in “/etc/httpd/conf.d/proxy_ajp.conf”.
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so |
Now let's configure Tomcat as below example, adding a virtual host:
<Host name="hello-test.mycompany.com" debug="0" appBase="/home/www/hello" unpackWARs="false" autoDeploy="false">
<Logger className="org.apache.catalina.logger.FileLogger" directory="logs" prefix="Hello." suffix=".log" timestamp="true"/> <Context path="" docBase="docs" debug="0" reloadable="true"/> </Host>
|
Now add a virtual host configuration file for Apache, “/etc/httpd/conf.d/vhost_hello.conf” (Suggested that using vhost_ + AppName or Hostname):
<VirtualHost 192.168.1.6:80> ServerAdmin [email protected] ServerName hello-test.mycompany.com ProxyPass / ajp://hello-test.mycompay.com:8009/ CustomLog /var/log/httpd/Hello.log combined </VirtualHost>
|
Finally modify “/etc/hosts” or using DNS resolve the new virtual host: (Make sure both the server and clients can resolve correctly. )
192.168.1.6 hello-test.mycompany.com |