Gentoo Wiki


Apache2 Series



Addons & Tunnels






Getting Started

First install Apache2 and Tomcat5.

Now, if they are running, shutdown Apache2 and Tomcat5 so that we can configure them to use mod_jk:

 /etc/init.d/tomcat5 stop
 /etc/init.d/apache2 stop 

Installing mod_jk

Make sure your USE flags reflect the version of apache you are using. (e.g. USE="apache2") This is extremely important as emerging mod_jk without the apache2 USE flag will automatically emerge apache 1.3 and not configure apache2 for use with mod_jk.

Unmasking mod_jk (ppc arch only)

File: /etc/portage/package.keywords
>=www-apache/mod_jk-1.2.19 ~ppc

Emerging mod_jk

 emerge -av mod_jk

Configuring Apache2 to use mod_jk

Define JK

File: /etc/conf.d/apache2

Note: Your APACHE2_OPTS may contain other options as well (e.g., -D PHP5). Do not remove these options when adding support for mod_jk.

Testing the Default Installation

By default, Tomcat5 should now be handling pages ending in ".jsp". To test this, start Tomcat5 and Apache2:

 /etc/init.d/apache2 start
 /etc/init.d/tomcat5 start

And browse to http://localhost/index.jsp. You should see the Tomcat5 welcome page, just as if you had browsed to http://localhost:8080.

If you are running a very simple webserver this setup may be perfectly fine for you. Remember, however, that pages ending in ".jsp" will be handled by Tomcat5 as if they were sent directly to port 8080--this means that you must configure Tomcat5 to serve these pages. For example, under the default Tomcat5 settings, index.jsp is served from /opt/Tomcat5/webapps/ROOT.

Advanced Topics & Setup

Advanced: Configuring mod_jk to Serve Other Files or Directories

You may also want to have Tomcat5 handle other file extensions or servlets. To add this capability, edit the 88_mod_jk.conf file in /etc/apache2/modules.d by adding jkMount statements. For example, to have Tomcat handle all requests for files in the /servlet directory we would add the following:

File: /etc/apache2/modules.d/88_mod_jk.conf file entry
jkMount /servlet/* ajp13

Advanced: Setting up mod_jk for Virtual Hosts

If you are running Apache2 with virtual hosts, you may not want each virtual host to have the ability to execute jsp's and servlets. In this case, you will need to comment out an jkMount statements found in /etc/apache2/modules.d/88_mod_jk.conf and instead add jkMount statements inside each of <Virtual Host *:80> tag of the vhosts for which you want mod_jk to work. For Example, if you had a vhost named

File: /etc/apache2/vhosts.d/01_www.gentoo.com_vhost.conf file entry
  <VirtualHost *:80>
     jkMount /*.jsp ajp13
     jkMount /servlet/* ajp13

External Links

Retrieved from ""

Last modified: Thu, 31 May 2007 05:11:00 +0000 Hits: 14,611