Before you begin
These instructions were written for Tomcat 4.1. Since the time of this writing a new version of Tomcat, Tomcat 5, has been released. In Tomcat 5, mod_jk2 is the perfered linking method. Continue reading this thread for more information about mod_jk2.
What will be done?
By default Tomcat is setup to use port 8080. In order to let users view your JSP or Servlet pages, they would have to navigate outside of your main Apache site. This also made using SSL in Java pages an impossibility. When linking your Tomcat server with your Apache server, Apache forwards its *.jsp and */servlet/* requests to Tomcat using an intermediate module, mod_jk. There is a more advanced module called mod_jk2 available, but due to its lack of any documentation, very few servers use it. mod_jk is preferred.
Setup Apache
If you already have Apache setup, great, skip this section. Otherwise just
Code: Select all
# emerge sync
# emerge apache
# rc-update add apache2 default
# /etc/init.d/apache2 startSetup Tomcat
In the following section you will setup the JSP and Servlet server, Tomcat 4.1.
Code: Select all
# emerge tomcatCode: Select all
# chmod 755 /etc/conf.d/tomcatCode: Select all
# rc-update add tomcat default
# /etc/init.d/tomcat startmod_jk will only work with Tomcat >= 4.0. If you are not using a JDK from Portage, you may have to specify your JDK's path in /etc/conf.d/tomcat.
Compile mod_jk
Download the latest source to mod_jk and unpack:
Code: Select all
$ wget http://jakarta.apache.org/builds/jakarta-tomcat-connectors/jk/release/v1.2.4/src/jakarta-tomcat-connectors-jk-1.2.4-src.tar.gz
$ tar -xvzf jakarta-tomcat-connectors-jk-1.2.4-src.tar.gzCode: Select all
# mkdir /usr/build
# updatedb
# locate config_vars.mkCode: Select all
# cp /usr/lib/apache2/build/config_vars.mk /usr/build/Code: Select all
$ cd jakarta-tomcat-connectors-jk-1.2.4-src/jk/native/
$ ./buildconf.sh
$ ./configure --with-apxs=/usr/sbin/apxs2
$ makeNow copy the module to a place safe place:
Code: Select all
# cp apache-2.0/mod_jk.so /usr/lib/apache2-extramodules/Open up /opt/tomcat/conf/server.xml in your favorite text editor. After the line
add<Server port="8005" shutdown="SHUTDOWN" debug="0">
and after the line<Listener className="org.apache.ajp.tomcat4.config.ApacheConfig" />
add<Host name="localhost" debug="0" appBase="webapps" unpackWARs="true" autoDeploy="true">
Save the file and restart Tomcat.<Listener className="org.apache.ajp.tomcat4.config.ApacheConfig" append="true" />
Code: Select all
# /etc/init.d/tomcat restartAs you see in the new mod_jk.conf there a line defining where the workers.properties file is. The workers.properties is a file that specifies mod_jk's linking type, ports, and loadbalancers if you want them. I have created the most simple workers.properties as possible. You should create this file in /opt/tomcat/conf/jk/.<IfDefine JK>
<IfModule !mod_jk.c>
LoadModule jk_module extramodules/mod_jk.so
</IfModule>
</IfDefine>
<IfModule mod_jk.c>
JkWorkersFile /opt/tomcat/conf/jk/workers.properties
JkLogFile /opt/tomcat/logs/mod_jk.log
JkLogLevel emerg
JkMount /admin ajp13
JkMount /admin/* ajp13
JkMount /webdav ajp13
JkMount /webdav/* ajp13
JkMount /examples ajp13
JkMount /examples/* ajp13
JkMount /tomcat-docs ajp13
JkMount /tomcat-docs/* ajp13
JkMount /manager ajp13
JkMount /manager/* ajp13
</IfModule>
Change the paths as necessary. To enable mod_jk in Apache, edit /etc/conf.d/apache2 to haveworkers.tomcat_home=/opt/tomcat
workers.java_home=/opt/blackdown-jdk-1.4
ps=/
worker.list=ajp13
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
Make sure APACHE2_OPTS is uncommented! Now restart Apache and navigate to http://localhost/tomcat-docs/. Since tomcat-docs has been "JkMount"ed, Apache will forward requests to Tomcat. If you see the Tomcat documentation, then everything has been set up correctly.APACHE2_OPTS="-D JK"
Well so much for my first post to the documentation forum. Please give me comments or ask me questions.



