Using ajp to forward requests to Tomcat from Apache
Since there are limited tcp ports on a computer, and we wanted apache (php) and tomcat (jsp) on the same development machine, it is necessary to share ports. To do this, we get apache to listen on the standard port 80, and configure it to forward any requests to certain directores to Tomcat.
It will use mod_jk, and create a tcp connection between apache and tomcat, and forward the request using ajp protocol.
Following are notes on how I installed it. Apache had already been compiled and was running nicely.
1. Install mod_jk into apache
Go to your closest apache distribution, inside the jakarta/tomcat-connectors/jk2/ directory get the source and unpack it.
You will have to specify where existing apache source code is.
$ cd jk/native $ ./buildconf.sh $ ./configure --with-apache=/home/compile/apache_1.3.29 $ make $ make install
This will install some stuff into the target apache source tree. Reconfigure and compile apache again, then install:
$ cd /home/compile/apache_1.3.29
$ ./config.status --activate-module=src/modules/jk/libjk.a \
--enable-module=dir \
--disable-shared=dir
$ make
$ make install
Restart apache and check that your old setup is still working
2. Configuration
workers.properties
Read up on what a worker is. In our case it is a tomcat instance that will do some work (by processing certain requests) on behalf of the web server.
bash-2.05a$ pwd /usr/local/apache/conf bash-2.05a$ cat workers.properties workers.apache_log=/usr/local/apache/logs workers.tomcat_home=/usr/local/tomcat workers.java_home=/usr/local/java/jdk1.2.2/ worker.list=aelst worker.aelst.type=ajp13 worker.aelst.host=localhost worker.aelst.port=8009 worker.aelst.lbfactor=50 worker.aelst.cachesize=10 worker.aelst.cache_timeout=600 worker.aelst.socket_keepalive=1 worker.aelst.socket_timeout=300
httpd.conf
You have to add some lines to the apache conf now.
JkWorkersFile /usr/local/apache/conf/workers.properties JkLogFile /usr/local/apache/logs/mod_jk.log JkLogLevel debug # Select the log format JkLogStampFormat "[%a %b %d %H:%M:%S %Y] " # JkOptions indicate to send SSL KEY SIZE, JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories # JkRequestLogFormat set the request format JkRequestLogFormat "%w %V %T" # Send servlet for context /examples to worker named worker1 JkMount /examples/* aelst
3. Restart the server
You can now restart apache and test that request urls under /examples are forwarded to tomcat.

