Term | Meaning |
---|---|
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. |
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. |
For example, the Tomcat 3.3 Release at
http://jakarta.apache.org/builds/jakarta-tomcat/release/v3.3/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/i386 | Contains the mod_jk.nlm and nsapi.nlm |
win32/i386 | 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 Tomcat 3.3 distribution of mod_jk will function correctly with other 3.x versions of Tomcat, such as Tomcat 3.2.1.
The steps that you need to take are:
MSDEV mod_jk.dsp /MAKE ALL
If msdev is not in your path, enter the full path to msdev.exe. Also, ApacheCore.lib is expected to exist in the APACHE1_HOME\src\Debug or APACHE1_HOME\src\Release (or the older APACHE1_HOME\src\CoreD or APACHE1_HOME\src\CoreR) directories before linking will succeed. You will need to build enough of the Apache source to create the required librarie(s).
An alternative will be to open mod_jk.dsp in msdev and build it using the build menu.
Build mod_jk.so. Following are three techniques you can try, in
order of simplicity:
# JAVA_INCLUDE="-I ${JAVA_HOME}/include -I ${JAVA_HOME}/include/linux"
Finally, you can try to build it manually. Run the apxs
command that came with your apache distribution (hint: look in /usr/local/apache/bin,
/usr/sbin, or wherever you installed apache). Type the command all on one
line.
For Linux:
apxs -o mod_jk.so -I../jk -I/usr/local/jdk/include -I/usr/local/jdk/include/linux -c *.c ../jk/*.cYour build may fail because the object files from the ../jk directory have been compiled to the current directory, rather than their source directory. Running gcc -shared -o mod_jk.so *.o should finish the build.
For Solaris:
Use the build-solaris.sh script as follows:
# sh build-solaris.shThis will build and install mod_jk.so in your apache/libexec directory. This script contains settings for your Java and Apache home locations. Make sure that these are set according to your installation. The default settings are JAVA_HOME=/usr/java and APACHE_HOME=/usr/local/apache. If your installation is different, you will need to edit the build-solaris.sh script and change these values appropriately.
See README.solaris located in TOMCAT_HOME/native/mod_jk/apache1.3 for more information.
If the build script does not work, you can also build mod_jk as follows:
$APACHE_HOME/bin/apxs -o mod_jk.so -DSOLARIS -I../jk -I/usr/java/include -I/usr/java/include/solaris -c *.c ../jk/*.c
For HP-UX 11.00:
Use the build-hpux.sh script as follows:
# sh build-hpux.shThis will build and install mod_jk.so in your apache/libexec directory. This script contains settings for your Java and Apache home locations. Make sure that these are set according to your installation. The default settings are JAVA_HOME=/opt/java1.3 and APACHE_HOME=/usr/local/apache. If your installation is different, you will need to edit the build-hpux.sh script and change these values appropriately.
Also note that there are two HP-UX build scripts. One script was written to build mod_jk without JNI support using GNU GCC. The other script builds mod_jk with JNI support, however, this script requires the HP ANSI C Compiler (not the stripped down C compiler included with HP-UX to rebuild the kernel). The HP Compiler is required because the dlopen() and related shared libraries are only available for 64-bit applications and reliable 64-bit compilation is not available with the current version of GCC.
The build-hpux.sh script should also work for HP-UX 10.00.
See README.hpux located in TOMCAT_HOME/native/mod_jk/apache1.3
for more information.
For other Unixes (including FreeBSD):
The build-hpux-cc.sh script should be modifiable for IRIX and
AIX. Edit the script and change the APACHE_HOME and JAVA_HOME locations
as required.
If you are using EAPI, try adding -DEAPI to the apxs command after mod_jk.so.
If apxs fails with 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.tmpl my $CFG_LDFLAGS_SHLIB = q(); # substituted via Makefile.tmpland change to:
my $CFG_LD_SHLIB = q(ld); # substituted via Makefile.tmpl my $CFG_LDFLAGS_SHLIB = q(-G); # substituted via Makefile.tmplIf you've installed Java in another directory, adjust accordingly.
For other Unixes you should be able to work it out, but remember that the order of the arguments to apxs is important!.
Include TOMCAT_HOME/conf/auto/mod_jk.conf
Example:
Include /usr/local/jakarta-tomcat/conf/auto/mod_jk.conf
This will tell Apache to use directives in the mod_jk.conf file in the Apache configuration. This file is created by starting Tomcat with the "jkconf" option. Tomcat will initialize, write the configuration file and then exit. This may be done while an instance of Tomcat is running. Options for controlling how the mod_jk configuration file is generated are described in the configuring Tomcat section below [Configuring Tomcat].
NOTE: If you plan to use the Tomcat generated 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/auto/mod_jk.conf file to your own configuration file, such as TOMCAT_HOME/conf/jk/mod_jk.conf.
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] "
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 beginning with /servlet 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
To have Tomcat generate the configuration file, start Tomcat with the "jkconf" option. Tomcat will initialize, write the configuration file, and then exit. This may be done while an instance of Tomcat is running.
The generation of the mod_jk configuration file is controlled by the ApacheConfig module. The default installation of Tomcat 3.3 comes with the ApacheConfig directive already present in the TOMCAT_HOME/conf/server.xml.
Note: Generating the mod_jk configuration file on demand is new in Tomcat 3.3. Older versions of Tomcat create the auto-config file without a directive in server.xml and generate it each time Tomcat is started. The new ApacheConfig directive in Tomcat 3.3 allows for additional configuration options as detailed later in this section. For older versions of Tomcat, refer 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/auto/mod_jk.conf is generated when tomcat starts, so you'll need to start Tomcat before Apache. Tomcat will overwrite TOMCAT_HOME/conf/auto/mod_jk.conf each startup so customized configuration should be kept elsewhere. For example, copy TOMCAT_HOME/conf/auto/mod_jk.conf to TOMCAT_HOME/conf/jk/mod_jk.conf before making changes. You'll need to start Tomcat with the "jkconf" option 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:
where options can include any of the following attributes:< ContextManager ... > ... <ApacheConfig options /> ... < /ContextManager >
... <ApacheConfig configHome="/home/mydir" /> ...
Note: The default mod_jk configuration file generated by:
differs from the file generated by Tomcat 3.2.x. In Tomcat 3.3, the default is to forward all requests to Tomcat for Tomcat's contexts (i.e. forwardAll="true"), excluding the root context. This helps ensure that behavior configured in web.xml files will function properly. The configuration that best matches Tomcat 3.2.x behavior is:<ApacheConfig />
With this configuration, JSP and servlet requests to the root context will be served from Tomcat's ROOT webapp. Other requests, such as for static files, will be served from Apache's DocumentRoot directory. If Apache's DocumentRoot isn't updated to point to Tomcat's ROOT webapp, then the root context will malfunction. For example, JSP's that reference ".gif" files in Tomcat's ROOT webapp will not be able to display them since they won't be found under Apache's DocumentRoot directory.<ApacheConfig forwardAll="false" noRoot="false" jkConfig="conf/mod_jk.conf-auto" jkDebug="error" />
The default installation of Tomcat 3.3 comes with connectors for both protocols in the TOMCAT_HOME/conf/server.xml. The default choice by the ApacheConfig directive will be to using the "ajp13" worker which uses the Ajpv13 protocol. Even though mod_jk uses the Ajpv13 by default, you shouldn't remove the Ajpv12 connector present in the server.xml file. The Ajpv12 connector is also used for shutting down Tomcat.
URLs ending in .jsp and beginning with /servlet are handled by Tomcat, the rest are handled by Apache. The files for each Host are server out of /web/host1 and /web/host2 respectively.
The example are over-simplified and incomplete but should get you started.
Also note, this form virtual host setup is new in Tomcat 3.3 and later - this example
won't work with Tomcat 3.2 and earlier..
. . <Ajp12Connector port="8007" /> <Ajp13Connector port="8009" /> . |
<?xml version="1.0" encoding="ISO-8859-1"?> <Server> <Host name="host1.apache.org"> <Context path="" docBase="/web/host1" debug="0"/> </Host> <Host name="host2.apache.org"> <Context path="" docBase="/web/host2" debug="0"/> </Host> </Server> |
# 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 (Ajp12 left to readers imagination) # worker.ajp13.port=8009 worker.ajp13.host=localhost worker.ajp13.type=ajp13 |
# 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> |
For additional help, the best resource is the Tomcat Users Discussion list. You should start by searching the mail list archives located at http://www.mail-archive.com/tomcat-user@jakarta.apache.org/ or http://mikal.org/interests/java/tomcat/index.jsp 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
Note: The above steps assume that you downloaded the Apache source and placed it in your /usr/local/src directory.# 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
Not Found The requested URL /login/j_security_check was not found on this server. |
JkMount /*.jsp ajp13 |
JkMount /*.vm ajp13 |
<login-config> <auth-method>FORM</auth-method> <realm-name>Protected</realm-name> <form-login-config> <form-login-page>/login/login.vm</form-login-page> <form-error-page>/login/error.vm</form-error-page> </form-login-config> </login-config> |
<form method="post" action="j_security_check"> |
JkMount /*.vm ajp13 JkMount /login/j_security_check ajp13 |
Revisions by (Alphabetical)
Mike Braden <mikeb@mwbinc.com>
Mike Bremford
Chris Pepper
With help from countless others on the tomcat-dev and tomcat-user lists!
Copyright ©1999-2001 The Apache Software Foundation
Legal Stuff They Make Us Say Contact Information |