The Jakarta Project
    The Tomcat Servlet/JSP Container

Links

Top Level Elements

Connectors

Containers

Nested Components

The AJP Connector

Introduction

The AJP Connector element represents a Connector component that communicates with a web connector via the AJP protocol. This is used for cases where you wish to invisibly integrate Tomcat 4 into an existing (or new) Apache installation, and you want Apache to handle the static content contained in the web application, and/or utilize Apache's SSL processing. In many application environments, this will result in better overall performance than running your applications under Tomcat stand-alone using the HTTP/1.1 Connector. However, the only way to know for sure whether it will provide better performance for your application is to try it both ways.

This connector supports load balancing when used in conjunction with the jvmRoute attribute of the Engine.

Attributes
Common Attributes

All implementations of Connector support the following attributes:

AttributeDescription
className

Java class name of the implementation to use. This class must implement the org.apache.catalina.Connector interface. You must specify the standard value defined below.

enableLookups

Set to true if you want calls to request.getRemoteHost() to perform DNS lookups in order to return the actual host name of the remote client. Set to false to skip the DNS lookup and return the IP address in String form instead (thereby improving performance). By default, DNS lookups are enabled.

redirectPort

If this Connector is supporting non-SSL requests, and a request is received for which a matching <security-constraint> requires SSL transport, Catalina will automatically redirect the request to the port number specified here.

scheme

Set this attribute to the name of the protocol you wish to have returned by calls to request.getScheme(). For example, you would set this attribute to "https" for an SSL Connector. The default value is "http". See SSL Support for more information.

secure

Set this attribute to true if you wish to have calls to request.isSecure() to return true for requests received by this Connector (you would want this on an SSL Connector). The default value is false.

Standard Implementation

The standard implementation of AJP Connector is org.apache.ajp.tomcat4.Ajp13Connector.

This implementation supports the AJP 1.3 and 1.4 protocols.

It supports the following additional attributes (in addition to the common attributes listed above):

AttributeDescription
acceptCount

The maximum queue length for incoming connection requests when all possible request processing threads are in use. Any requests received when the queue is full will be refused. The default value is 10.

address

For servers with more than one IP address, this attribute specifies which address will be used for listening on the specified port. By default, this port will be used on all IP addresses associated with the server.

debug

The debugging detail level of log messages generated by this component, with higher numbers creating more detailed output. If not specified, this attribute is set to zero (0).

maxProcessors

The maximum number of request processing threads to be created by this Connector, which therefore determines the maximum number of simultaneous requests that can be handled. If not specified, this attribute is set to 20.

NOTE:For Apache 1.3 on Unix there is a 1 to 1 mapping between httpd processes and Ajp13Processors. You must configure maxProcessors to be greater than or equal to the maximum number of httpd processes your Apache web server spawns.

minProcessors

The number of request processing threads that will be created when this Connector is first started. This attribute should be set to a value smaller than that set for maxProcessors. The default value is 5.

port

The TCP port number on which this Connector will create a server socket and await incoming connections. Your operating system will allow only one server application to listen to a particular port number on a particular IP address.

tomcatAuthentication

This flag, which value defaults to true, indicates whether or not authentication will be handled by Tomcat or the native web server. If the attribute value is true, any pricipal authenticated by the native web server will be ignored, and Tomcat will take care of the authentication. If the attribute value is false, Tomcat will not attempt to authenticate a principal if the native web server has already authenticated one.

Nested Components

Configuration HOWTOs
Apache
Introduction

This section explains how to connect Tomcat 4 to the popular open source web server, Apache. It was originally part of Tomcat: A Minimalistic User's Guide by Gal Shachor, but has been split off for organizational reasons. It should be considered a work in progress. Since the Tomcat source tree is constantly changing, the information herein may be out of date. The only definitive reference at this point is the source code.

Installation
Needed Components

In a nutshell a web server is waiting for client HTTP requests. When these requests arrive the server does whatever is needed to serve the requests by providing the necessary content. Adding a servlet container may somewhat change this behavior. Now the web server needs also to perform the following:

  • Load the servlet container adapter library and initialize it (prior to serving requests).
  • When a request arrives, it needs to check and see if a certain request belongs to a servlet, if so it needs to let the adapter take the request and handle it.

The adapter on the other hand needs to know what requests it is going to serve, usually based on some pattern in the request URL, and to where to direct these requests.

Things are even more complex when the user wants to set a configuration that uses virtual hosts, or when they want multiple developers to work on the same web server but on different servlet container JVMs. We will cover these two cases in the advanced sections.

mod_jk Terminology

The following terms are used in this section:

  • Worker process - A worker is a Tomcat instance that is running to serve servlet requests coming from the web server. In most cases there is only a single worker (the one and only Tomcat process) but sometimes you will run multiple workers to achieve load balancing or site partitioning. Each worker is identified to the web server by the host were it is located, the port where it listens and the communication protocol used to exchange messages.
  • In-Process Worker - This is a special worker. Instead of working with a Tomcat process residing on another process, the web server opens a JVM and executes Tomcat inside the web server process address space. Our discussion in this document is not going to get into this special worker. Note: Tomcat 4 can't be run as this type of worker at the moment.
  • Web Server Plug-in/Tomcat Redirector - For Tomcat to cooperate with any web server it needs an "agent" to reside in the web server and send him servlet requests. This is the web server plug-in, and in our case the web server plug-in is mod_jk. The redirector usually comes in the shape of a DLL or shared object module that you plug into the web server.
  • Plug-in Configuration - We need to configure the web server plug-in so that it knows where the different Tomcat workers are and to which of them it should forward requests. This information, accompanied with some internal parameter, such as the log level, comprises the plug-in configuration.
  • Web Server Configuration - Each web server has some configuration that defines its behavior, e.g. on which port to listen, what files to serve, what web server plug-ins to load, etc. You will need to modify your web server configuration to instruct it to load the Tomcat redirector mod_jk.
Getting mod_jk

The mod_jk source now resides in the jakarta-tomcat-connectors subproject. Please refer to it for build instructions.

Binaries for mod_jk are available for several platforms in the same 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.

Note: Note: The version of mod_jk is not dependent on the version of Tomcat. The Tomcat 3.3 distribution of mod_jk will function correctly with Tomcat 4.x and other 3.x versions of Tomcat, such as Tomcat 3.2.1.

Configuring Apache

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!

Like Tomcat 3, Tomcat 4 can automatically generate the necessary $CATALINA_HOME/conf/mod_jk.conf, but it can also be created manually. Note that Tomcat and Apache must be restarted after adding a new context. See the "Using ApacheConfig" section for more details.

The basic configuration is as follows:

  • You will need to instruct Apache to load Tomcat. This can be done with Apache's LoadModule and AddModule configuration directives.
  • You must inform mod_jk the location of your workers.properties file. Use mod_jk's JkWorkersFile configuration directive.
  • You should specify a location where mod_jk is going to place its log file and a log level to be used. Use the JkLogFile and JkLogLevel configuration directives. Possible log levels are debug, info, error and emerg. If the JkLogLevel is not specified, no log is generated.
  • The directive JkLogStampFormat will configure the date/time format found on mod_jk logfile. Using strftime() format string it's set by default to "[%a %b %d %H:%M:%S %Y] "
  • 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. You can use the JkMount directive at the top level or inside <VirtualHost> sections of your httpd.conf file.
Configuring Tomcat

Tomcat 4 can be configured to automatically generate the Apache configuration file. The next section describes how to enable this option.

After enabling the AJP 1.3 connector, you need to define workers, using a $CATALINA_HOME/conf/workers.properties file. In most cases, using the example workers.properties given below should work fine, after changing the path values to reflect how your environment is set up.

Using ApacheConfig

Tomcat 4 provides extra flexability over Tomcat 3 in setting up the automatic generation of the Apache configuration file. However, this comes at the cost of a bit more complexity. Each time that Tomcat is started, it will write the configuration file to $CATALINA_HOME/conf/auto/mod_jk.conf. You can then either

Include $CATALINA_HOME/conf/auto/mod_jk.conf
in your httpd.conf file.

To generate the global Apache directives (e.g. LoadModule, JkLogFile), you define a Server Listener:

   <Server port="8005" shutdown="SHUTDOWN" debug="0">
     <Listener className="org.apache.ajp.tomcat4.config.ApacheConfig" />
     ...

To configure the individual context information, you then either define a Host Listener or a Context Listener depending on if you are using virutal hosting or not. Defining a Host Listener will generate the Apache <VirtualHost> directive and include all of the configurations for the Contexts under this host. Using the Context Listener allows you the flexability to configure the Context the same way even if it is being served from several hosts.

Except for the placement of the <Listener ...>, the syntax is virtualy identical for the Host Listener and the Context Listener. The examples that follow will demonstrate the functionality for a Host Listener. The simplest configuration is:

    <Host name="localhost" debug="0" appbase="webapps" >
      <Listener className="org.apache.ajp.tomcat4.config.ApacheConfig" 
          append="true" />

It is possible to modify the output configuration file with the following attributes:

AttributeDescription
configHome Default parent directory for the following paths. If not set, this defaults to CATALINA_HOME. Ignored whenever any of the following paths is absolute
jkConfig Path to write apacke mod_jk conf file to. If not set, defaults to "conf/auto/mod_jk.conf".
workersConfig Path to workers.properties file used by mod_jk. If not set, defaults to "conf/jk/workers.properties".
modJk Path to Apache mod_jk plugin file. If not set, defaults to "modules/mod_jk.dll" on windows, "modules/mod_jk.nlm" on netware, and "libexec/mod_jk.so" everywhere else.
jkLog Path to log file to be used by mod_jk
jkDebug JK Loglevel setting. May be debug, info, error, or emerg. If not set, defaults to no log.
jkWorker The desired worker. Must be set to one of the workers defined in the workers.properties file. "ajp13" or "inprocess" are the workers found in the default workers.properties file. If not specified, defaults to "ajp13".
forwardAll If true, forward all requests to Tomcat. This helps ensure that all the behavior configured in the web.xml file functions correctly. If false, let Apache serve static resources. The default is true. Warning: When false, some configuration in the web.xml may not be duplicated in Apache. Review the mod_jk conf file to see what configuration is actually being set in Apache.
noRoot If true, the root context is not mapped to Tomcat. If false and forwardAll is true, all requests to the root context are mapped to Tomcat. If false and forwardAll is false, only JSP and servlets requests to the root context are mapped to Tomcat. When false, to correctly serve Tomcat's root context you must also modify the DocumentRoot setting in Apache's httpd.conf file to point to Tomcat's root context directory. Otherwise some content, such as Apache's index.html, will be served by Apache before mod_jk gets a chance to claim the request and pass it to Tomcat. The default is true.
append Append to the current configuration file.
Example Configuration Files

Excerpt from workers.properties showing the Ajp13 worker:

# Setup for Solaris system
#
workers.tomcat_home=/usr/local/jakarta-tomcat
workers.java_home=/usr/java
ps=/
worker.list=ajp12, ajp13

# Definition for Ajp13 worker
#
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13

Excerpt from Apaches httpd.conf showing JK directives:

# Load mod_jk
#
LoadModule jk_module libexec/mod_jk.so
AddModule mod_jk.c

# Configure mod_jk
#
JkWorkersFile /usr/local/jakarta-tomcat/conf/jk/workers.properties
JkLogFile /usr/local/apache/logs/mod_jk.log
JkLogLevel info

# First Virtual Host.
#
<VirtualHost 10.0.0.1:80>
DocumentRoot /web/host1
ServerName host1.apache.org
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
</VirtualHost>

# Second Virtual Host. Also accessible via HTTPS
#
<VirtualHost 10.0.0.2:80>
DocumentRoot /web/host2
ServerName host2.apache.org
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
</VirtualHost>

<VirtualHost 10.0.0.2:443>
DocumentRoot /web/host2
ServerName host2.apache.org
SSLEngine On
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
</VirtualHost>
IIS 4.x and 5.x
Introduction

This section explains how to set up IIS 4.0 or newer to cooperate with Tomcat 4. Normally IIS cannot execute Servlets and Java Server Pages (JSPs), configuring IIS to use Tomcat redirector plugin will allow IIS to redirect Servlet and JSP requests to Tomcat.

The Tomcat redirector for IIS is composed of four entities:

  • isapi_redirect.dll - The IIS server plugin, either obtain a pre-built DLL or build it yourself (see the build section).
  • worker.properties - A file that describes the host(s) and port (s) used by the workers (Tomcat processes).
  • uriworkermap.properties - A file that maps URL-Path patterns to workers.
  • iis_redirect.reg - A file that creates registry entries in the Windows registry.

Installation

Make sure the Tomcat AJP connector is properly declared in the Catalina configuration file.

Download isapi_redirect.dll for Tomcat 3.3 release or use the following link.

You can then either manually define a few extra configuration files (read below), or use the automatic IISConfig to have Tomcat generate them for you (see next section).

The next step is to create worker.properties to help isapi_redirect.dll to identify where to find Tomcat and its configuration.

Next, the ISAPI filter for Tomcat must be configured to redirect requests for specific webapps to Tomcat.

Then the uriworkermap.properties file must be created in %CATALINA_HOME%\conf directory.

Note: See below for examples of the configuration files. Those configuration files assume Tomcat is installed in the c:\jakarta-tomcat-4.0.1 directory.

Using IISConfig

Tomcat 4 provides extra flexability over Tomcat 3 in setting up the automatic generation of the IIS configuration file. However, this comes at the cost of a bit more complexity. Each time that Tomcat is started, it will write the configuration file to %CATALINA_HOME%/conf/auto/uriworkersmap.properties. If enabled as a Server Listener, it will also write the required registry entries to %CATALINA_HOME%/conf/auto/iis_redirect.reg. You may enter the settings into the registry by double-clicking on this file from the Windows Explorer.

To generate the global IIS directives (including the registry file), you define a Server Listener:

   <Server port="8005" shutdown="SHUTDOWN" debug="0">
     <Listener className="org.apache.ajp.tomcat4.config.IISConfig" />
     ...

To configure the individual context information, you then either define a Host Listener or a Context Listener depending on if you are using virutal hosting or not. Defining a Host Listener will include all of the configurations for the Contexts under this host. Using the Context Listener allows you the flexability to configure the Context the same way even if it is being served from several hosts.

Except for the placement of the <Listener ...>, the syntax is virtualy identical for the Host Listener and the Context Listener. The examples that follow will demonstrate the functionality for a Host Listener. The simplest configuration is:

    <Host name="localhost" debug="0" appbase="webapps" >
      <Listener className="org.apache.ajp.tomcat4.config.IISConfig" 
          append="true" />

It is possible to modify the output configuration file with the following attributes:

AttributeDescription
configHome Default parent directory for the following paths. If not set, this defaults to CATALINA_HOME. Ignored whenever any of the following paths is absolute.
regConfig Path to use for writing the registry settings configuration file. If not set, defaults to "conf/auto/iis_redirect.reg".
uriConfig Path to use for writing the URI worker map configuration file. If not set, defaults to "conf/auto/uriworkermap.properties".
workersConfig Path to workers.properties file used by mod_jk. If not set, defaults to "conf/jk/workers.properties".
jkLog path to log file to be used by mod_jk
jkDebug JK Loglevel setting. May be debug, info, error, or emerg. If not set, defaults to no emerg.
jkWorker The desired worker. Must be set to one of the workers defined in the workers.properties file. "ajp13" or "inprocess" are the workers found in the default workers.properties file. If not specified, defaults to "ajp13".
forwardAll If true, forward all requests to Tomcat. This helps ensure that all the behavior configured in the web.xml file functions correctly. If false, let IIS serve static resources. The default is true. Warning: When false, some configuration in the web.xml may not be duplicated in IIS. Review the mod_jk conf file to see what configuration is actually being set in IIS.
noRoot If true, the root context is not mapped to Tomcat. If false and forwardAll is true, all requests to the root context are mapped to Tomcat. If false and forwardAll is false, only JSP and servlets requests to the root context are mapped to Tomcat. When false, to correctly serve Tomcat's root context you must also modify the DocumentRoot setting in IIS's httpd.conf file to point to Tomcat's root context directory. Otherwise some content, such as IIS's index.html, will be served by IIS before mod_jk gets a chance to claim the request and pass it to Tomcat. The default is true.
append Append to the current configuration file.
Configuring IIS

  • Launch Internet Service Manager
  • Stop the Web Site if it is running
  • Create a virtual directory, by clicking on the default web site
    • Type the alias to say jakarta, press Next
    • Set the directory to %CATALINA_HOME%\bin where you installed isapi_redirect.dll, press next
    • Provide only read and execute privileges for security purposes
  • Add a filter to the default web site, using the IIS Management Console, right click on the properties and go to ISAPI filters tab. Press Add button, add isapi_redirect.dll as a filter the name of the filter should reflect its task (for example, "Jakarta Redirector"). The Executable field should point to the place where we installed isapi_redirect.dll, in our case %CATALINA_HOME%\bin\isapi_redirect.dll
  • If not done yet, enter the keys from iis_redirect.reg in the Windows registry (this can be done by double-clicking on the file in the explorer). Note: When manually creating the file (maybe from the example given below), remember to correct the directories where Tomcat is installed.
  • Startup IIS.
  • Go to the Properties of the web site and select the ISAPI filters tab to make sure that the ISAPI filter got registered correctly. It should have a Green arrow alongside it. Note: it is recommended to restart computer for the ISAPI filter to load.

Sample worker.properties file

# ************ Begin worker.properties **************
worker.ajp13.type=ajp13

#
# Specifies the load balance factor when used with
# a load balancing worker.
# Note:
#  ----> lbfactor must be > 0
#  ----> Low lbfactor means less work done by the worker.
worker.ajp13.lbfactor=1

#
# Specify the size of the open connection cache.
#worker.ajp13.cachesize

#
#------ DEFAULT LOAD BALANCER WORKER DEFINITION ----------------------
#---------------------------------------------------------------------
#

#
# The loadbalancer (type lb) worker perform weighted round-robin
# load balancing with sticky sessions.
# Note:
#  ----> If a worker dies, the load balancer will check its state
#        once in a while. Until then all work is redirected to peer
#        worker.
worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=ajp13

#
# worker.tomcat_home should point to the location where you
# installed tomcat. This is where you have your conf, webapps and lib
# directories.
#
worker.tomcat_home=C:\jakarta-tomcat-4.0.1

#
# worker.java_home should point to your Java installation. Normally
# you should have a bin and lib directories beneath it.
#
worker.java_home=C:\jdk1.3.1

#
# You should configure your environment slash... ps=\ on NT and / on UNIX
# and maybe something different elsewhere.
#
ps=\

#
#------ ADVANCED MODE ------------------------------------------------
#---------------------------------------------------------------------
#

#
#------ DEFAULT worker list ------------------------------------------
#---------------------------------------------------------------------
#
# The worker that your plugins should create and work with
worker.list=ajp13

#
#------ DEFAULT ajp13 WORKER DEFINITION ------------------------------
#---------------------------------------------------------------------
#

#
# Defining a worker named ajp13 and of type ajp13
# Note that the name and the type do not have to match.
#
worker.ajp13.port=8009
worker.ajp13.host=localhost

# ************ End worker.properties **************

Sample uriworkermap.properties

# *********** Begin uriworkermap.properties ***
#
# Simple worker configuration file
#

# Mount the Servlet context to the ajp13 worker
/servlet/*=ajp13

# Mount the examples context to the ajp13 worker
/examples/*=ajp13

# Advanced mount of the examples context
# /examples/servlet/*=ajp13
# ************* End uriworkermap.properties ****

iis_redirect.reg

REGEDIT4
[HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Jakarta Isapi Redirector\1.0]
"extension_uri"="/jakarta/isapi_redirect.dll"
"log_file"="C:\\jakarta-tomcat-4.0.1\\logs\\iis_redirect.log"
"log_level"="emerg"
"worker_file"="C:\\jakarta-tomcat-4.0.1\\conf\\worker.properties"
"worker_mount_file"="C:\\jakarta-tomcat-4.0.1\\conf\\uriworkermap.properties"


Copyright © 1999-2002, Apache Software Foundation