![]() |
![]() |
By Gal Shachor <shachor@il.ibm.com>
mod_jk is a replacement to the elderly mod_jserv. It is a completely new Tomcat-Apache plug-in that handles the communication between Tomcat and Apache.
Several reasons:
You will need to get to know a new simplified configuration mechanism. The advantage is that learning this mechanism will give you a head start if you want to deploy Tomcat on Apache and other web servers, such as Microsoft's Internet Information Server (IIS) and the iPlanet Enterprise Web Server.
Originaly mod_jk was included in Tomcat 3.2 and next in 3.3 CVS repository,
causing major headaches to maintain 2 set of identical code.
In 2001, all the connectors works was moved outside Tomcat 3.2/3.3 (for
mod_jk) and Tomcat 4.0 (for mod_webapp) in a new repository called jakarta-tomcat-connectors,
where all connector oriented development is now conducted.
In this repository you'll find native and java code, various native connectors
like mod_jk (jk/native), mod_jk2 (jk/native2), mod_webapp, you'll find also
the java side of these connectors (jk/java and webapp/java).
As such mod_jk could be used today by all of the ASF Tomcat Engine, 3.2.x,
3.3.x, 4.0.x, 4.1.x and 5.x.
In this document I am going to use a few terms, so let's define them:
mod_jk can be obtained in two formats - binary and source. Depending on the platform you are running your web server on, a binary version of mod_jk may be available. It is recommended to use the binary version if one is available. If the binary is not available, follow the instructions for building mod_jk from source. Notes at the end of this section offer recommendations for specific platforms.
The binaries for mod_jk are now available, for several platforms, in a separate area as the Tomcat Binary Release. The binaries are located in subdirectories by platform. For some platforms, such as Windows, this is the typical way of obtaining mod_jk since most Windows systems do not have C compilers. For others, the binary distribution of mod_jk offers simpler installation.
For example mod_jk 1.2.0 located at http://jakarta.apache.org/builds/jakarta-tomcat-connectors/jk/release/v1.2.0/bin/ contains the following:
linux/i386/ | Contains mod_jk.so for Apache 1.3 for the standard API as well as EAPI and mod_jk.so for Apache 2.0 |
netware/ | Contains the mod_jk.nlm and nsapi.nlm |
rpms/ |
Contains the rpms (including sources and i386
architectures) |
win32/ | Contains the mod_jk.dll for Windows as well as other useful binaries. |
Check the site for the latest binaries.
Note: The version of mod_jk is not dependent on the version of Tomcat. The mod_jk 1.2.0 distribution will function correctly with Tomcat 3.2 up to Tomcat 5.
mod_jk is available in source distribution for all Windows and most Unix platforms. The source for mod_jk live next to the Binary Distribution :
http://jakarta.apache.org/builds/jakarta-tomcat-connectors/jk/release/v1.2.0/src/
This directory is organized by Web Server name and version. Each
directory contains the source as well as the appropriate build scripts,
make files, or project files.
The redirector was developed using Visual C++ version 6.0, so having this environment is a prerequisite if you want to perform a custom build.
The steps that you need to take are:
This will build both release and debug versions of the redirector plug-in (mod_jk).
An alternative will be to open mod_jk.dsp in msdev and build it using the build menu.
./buildconf.sh (not required if there is allready the configure script)
./configure [autoconf arguments] [jakarta-tomcat-connectors arguments]
make
LDFLAGS=-lc ./configure -with-apxs=/home2/local/apache/bin/apxs
./configure --with-apxs=/opt/apache2/bin/apxs --with-java-home=${JAVA_HOME} --with-java-platform=2 --enable-jniApache 1.3, no JNI support:
./configure --with-apxs=/usr/sbin/apxs
Apache related parameters |
|
---|---|
--with-apxs[=FILE] |
FILE is the location of the apxs tool. Default is finding apxs in
PATH. |
--with-apache=DIR |
DIR is the path where apache sources are located. |
--enable-EAPI |
This parameter is needed when using Apache-1.3 and mod_ssl, otherwise
you will get the error message: |
--with-java-platform=VAL |
VAL is the Java platform 1 is 1.1.x and 2 is for 1.2 anf higher, should be guessed correctly. |
JNI related parameters |
|
---|---|
--enable-jni |
Build the JNI worker and so the build process
will require some informations about your Java Environment |
--with-java-home=DIR |
DIR is the patch to the JDK root directory. Something like: /opt/java/jdk12 |
--with-os-type[=SUBDIR] |
SUBDIR is the os-type subdirectory, normaly configure should guess it correctly. |
--with-arch-type[=SUBDIR] |
SUBDIR is the arch subdirectory, normaly configure should guess it correctly. |
--with-java-platform=VAL |
VAL is the Java platform 1 is 1.1.x and 2 is for 1.2 anf higher, should be guessed correctly. |
apxs:Break: Command failed with rc=255
,
it may have been damaged by mod_ssl. :Search for: my $CFG_LD_SHLIB = q(); # substituted via Makefile.tmpland change to:
my $CFG_LDFLAGS_SHLIB = q(); # substituted via Makefile.tmpl
my $CFG_LD_SHLIB = q(ld); # substituted via Makefile.tmpl
my $CFG_LDFLAGS_SHLIB = q(-G); # substituted via Makefile.tmpl
There are several Makefiles in the other directories under the TOMCAT_HOME/native/mod_jk/ directory. You should also check the Tomcat documentation for specific information related to other web servers.
This section details the configuration that is required for the Apache Web Server to support mod_jk.
If you've previously configured Apache to use mod_jserv, remove any ApJServMount directives from your httpd.conf. If you're including tomcat-apache.conf or tomcat.conf, you'll want to remove them as well - they are specific to mod_jserv. The mod_jserv configuration directives are not compatible with mod_jk!
The simplest way to configure Apache to use mod_jk is to turn on the Apache auto-configure setting in Tomcat and put the following include directive at the end of your Apache httpd.conf file (make sure you replace TOMCAT_HOME with the correct path for your Tomcat installation:
Include TOMCAT_HOME/conf/jk/mod_jk.conf-auto
Example:
Include /usr/local/jakarta-tomcat/conf/jk/mod_jk.conf-auto
This will tell Apache to use directives in the mod_jk.conf-auto file in the Apache configuration. This file is created by enabling the Apache auto-configuration as described in the configuring Tomcat section below [Configuring Tomcat].
NOTE: If you plan to use the Tomcat-Apache auto-configuration, skip the rest of this section and continue with the Configuring Tomcat section.
Custom configurations can be created by enabling the auto-configuration and copying the TOMCAT_HOME/conf/jk/mod_jk.conf-auto file to your own configuration file, such as TOMCAT_HOME/conf/jk/mod_jk.conf-local.
The basic configuration is as follows:
LoadModule jk_module libexec/mod_jk.so
AddModule mod_jk.c
JkWorkersFile /usr/local/jakarta-tomcat/conf/workers.properties
JkLogFile /usr/local/apache/logs/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
If you have created a custom or local version of mod_jk.conf-local as noted above, you can change settings such as the workers or URL prefix.
Use mod_jk's JkMount directive to assign specific URLs to Tomcat. In general the structure of a JkMount directive is:
JkMount <URL prefix> <Worker name>
For example the following directives will send all requests ending in .jsp or with /servlet as the second path componenet to the "ajp13" worker, but jsp requests to files located in /otherworker will go to "remoteworker".
You can use the JkMount directive at the top level or inside <VirtualHost> sections of your httpd.conf file.JkMount /*.jsp ajp13
JkMount /*/servlet/ ajp13
JkMount /otherworker/*.jsp remoteworker
If the Tomcat Host appBase (webapps) directory is accessible by the Apache web server, Apache can be configured to serve web application context directory static files instead of passing the request to Tomcat.
Caution: If Apache is configured to serve static pages for a web application it bypasses any security contraints you may have configured in your web application web.xml config file.
Use Apache's Alias directive to map a single web application context directory into Apache's document space for a VirtualHost:
# Static files in the examples webapp are served by apache
Alias /examples /export/home/web/host1/webapps/examples
JkMount /*.jsp ajp13
JkMount /*/servlet/ ajp13
Use the mod_jk JkAutoAlias directive to map all web application context
directories into Apache's document space. Attempts to access the WEB-INF
or META-INF
directories within a web application context or
a Web Archive *.war
within the Tomcat Host appBase (webapps)
directory will fail with an HTTP 403, Access Forbidden.
Example configuration for an Apache VirtualHost:
# Static files in all Tomcat webapp context directories are served by apache
JkAutoAlias /export/home/web/host2/webapps
JkMount /*.jsp ajp13
JkMount /*/servlet/ ajp13
In most simple cases Tomcat can generate the needed Apache configuration. You can configure Tomcat so that when it starts up it will automatically generate a configuration file for Apache to use mod_jk. Most of the time you don't need to do anything but include this file (appending "Include TOMCAT_HOME/conf/jk/mod_jk.conf-auto") in your httpd.conf, as shown in the previous section (Configuring Apache).
To configure Tomcat to generate the Apache auto-configuration add the following block to your TOMCAT_HOME/conf/server.xml file after <AutoWebApp ... />.
<ApacheConfig />
That's it, you can now start Tomcat and Apache and access Tomcat from the Apache server.
Note: Settings for mod_jk auto-configuration is new in Tomcat 3.3. Older versions of Tomcat create the auto-config file without a directive in server.xml. The new directive in Tomcat 3.3 allows for additional configuration options as detailed later in this section. For older versions of Tomcat, refere to the documentation that came with that version.
If you have special needs, for example mounting URL prefixes that are not the default, you can use this file as a base for your customized configuration and save the results in another file. If you manage the Apache configuration yourself you'll need to update it whenever you add a new context.
Note that you must restart tomcat and apache after adding a new context; Apache doesn't support configuration changes without a restart. Also the file TOMCAT_HOME/conf/jk/mod_jk.conf-auto is generated when tomcat starts, so you'll need to start Tomcat before Apache. Tomcat will overwrite TOMCAT_HOME/conf/jk/mod_jk.conf-auto each startup so customized configuration should be kept elsewhere. For example, copy TOMCAT_HOME/conf/jk/mod_jk.conf-auto to TOMCAT_HOME/conf/jk/mod_jk.conf-local before making changes. You'll need to startup Tomcat once to generate this file with your configuration for the first time.
It is also possible to specify the location of the auto generated files by setting options in the <ApacheConfig /> block. The following details the syntax:
< ContextManager ... >
...
<ApacheConfig options />
...
< /ContextManager >
where options can include any of the following attributes:
Example:
...
<AutoWebApp dir="webapps" host="DEFAULT" />
<ApacheConfig confighome="/home/mydir" />
...
<RequestInterceptor
className="org.apache.tomcat.modules.server.Ajp13Interceptor"
port="8009"/>
The server.xml file already has a block similar to this for Ajp12 connections on port 8007 (as delivered by mod_jserv). Even if you think you're only using Ajp13, you probably don't want to delete this connector -- it's required to shut down Tomcat.
Workers are configured using the file TOMCAT_HOME/conf/jk/workers.properties. There is a great deal of information in the workers.properties howto document, and you should really look at that first. If you're in a hurry however, you can probably get away with editing the file workers.properties and setting the workers.tomcat_home, workers.java_home and ps variables to the correct values for your system.
. |
# Setup for Solaris system |
# Load mod_jk |
For additional help, the best resource is the Tomcat Users Discussion list. You should start by searching the mail list archives located at http://mikal.org/interests/java/tomcat/index.html before you post questions to the list. If you are unable to locate the answer to your question in the archive, you can post questions about Tomcat or mod_jk to the user list for assistance. Make sure that you include the version of Apache and Tomcat that you are using as well as the platform you are running on. http://jakarta.apache.org/site/mail.html
# cd /usr/local/src
# gzip -dc apache_1.3.19.tar.gz|tar xvf -
# cd apache_1.3.19
# ./configure --prefix=/usr/local/apache \
--enable-module=most \
--enable-shared=max
# make
# make install
Note: The above steps assume that you downloaded the Apache source and
placed it in your /usr/local/src directory.
export LD_LIBRARY_PATH=$jre/bin:$jre/bin/classic:$LD_LIBRARY_PATHAlso some Linux distributions have enabled a GLIBC feature called 'floating stacks' which may not works with kernel less than 2.4.10 on SMP machines. You should disable floating stacks by exporting an environment variable :
export LD_ASSUME_KERNEL=2.2.5You could have to update your service scripts, ie /etc/rc.d/init.d/httpd, to set these env vars before your httpd server starts.
This document was originally created by Gal Shachor
Revisions by (Alphabetical)
Mike Braden <mikeb@mwbinc.com>
Mike Bremford
Henri Gomez <hgomez@apache.org>
Glenn Nielsen
Chris Pepper
With help from countless others on the tomcat-dev and tomcat-user lists!
Copyright ©1999-2001 The Apache
Software Foundation |