KEMBAR78
Configure Apache 2 with Tomcat 6 | PDF | Apache Http Server | Java Server Pages
0% found this document useful (0 votes)
114 views4 pages

Configure Apache 2 with Tomcat 6

The document provides steps to configure Apache 2 as a front-end server to Tomcat 6 to serve dynamic Java content. It describes downloading and configuring the JK module to enable Apache and Tomcat to communicate via the AJP protocol on port 8009. Requests for certain web contexts are mapped in Apache's configuration to the "ajp13" worker defined in the workers.properties file. Starting both Apache and Tomcat allows the configured web contexts to be accessed via the Apache server on port 8000.

Uploaded by

Sirish Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
114 views4 pages

Configure Apache 2 with Tomcat 6

The document provides steps to configure Apache 2 as a front-end server to Tomcat 6 to serve dynamic Java content. It describes downloading and configuring the JK module to enable Apache and Tomcat to communicate via the AJP protocol on port 8009. Requests for certain web contexts are mapped in Apache's configuration to the "ajp13" worker defined in the workers.properties file. Starting both Apache and Tomcat allows the configured web contexts to be accessed via the Apache server on port 8000.

Uploaded by

Sirish Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

8/11/2010 Howt to configure Apache 2 with To…

Apache 2 with Tomcat 6


How To Configure

How to Connect Tomcat 6 to Apache HTTP Serv er 2


Tomcat can be run as a standalone server. However, in a production environment, Tomcat is
often run as an add-on to the Apache HTTP Server (or Microsoft IIS) - as the Java servlet/JSP
container. In this combination, Tomcat executes the Java servlets and JSPs, the Apache serves the
static HTML pages and performs other server-side functions such as CGI, PHP, SSI, etc. The
reasons Tomcat is not often used as a standalone server for production are (extracted from
"tomcat-apache-howto"):
Tomcat is not as fast as Apache when it comes to static pages.
Tomcat is not as configurable as Apache.
Tomcat is not as robust as Apache.
Tomcat may not address many sites' need for functionality found only in Apache modules
(e.g. Perl, PHP, etc.).

To configure Tomcat to work with Apache HTTP Server, you should first read the documentation
provided in Tomcat thoroughly, and read the "Tomcat Connector" documents @
http://tomcat.apache.org/connectors-doc/.

To run Tomcat together with Apache:


Apache needs to load a "adapter" module, which uses a certain protocol, such as Apache JServ
Protocol (AJP) v1.2, v1.3, or WARP v1.0, to communicate with the Tomcat, via another TCP
port (port 8009 in the default configuration).
When Apache receives an HTTP request, it checks if the request belongs to Tomcat. If so, it
lets the adapter takes the request and forwards it to Tomcat, as illustrated below.

There are a few adapter modules available, such as Apache JServ Protocol (AJP) v1.2 "JServ"
module (outdated), AJP v1.3 "JK 1.2" module (in use) and "JK 2" module (deprecated). I will only
describe the JK1.2 module with Apache 2 here.
…ntu.edu.sg/…/apache_tomcat_howt… 1/4
8/11/2010 Howt to configure Apache 2 with To…

The step-by-step procedure is as follow:

Step 0.1: Install Apache HTTP Server


Refer to "Apache HTTP Server - How To". I shall assume that Apache is installed in directory
"c:\apache", and runs on port 8000.

Step 0.2: Install Tomcat


Refer to "Tomcat - How To". I shall assume that Tomcat is installed in directory "c:\tomcat", runs
on port 8080, and has a web context with URL Path called "/ws", which maps to document base
directory at "d:\workshop".

Step 1: Download the Apache-Tomcat Connector


An Apache-Tomcat connector - JK1.2 module - which is an adapter module used by Apache to
communicate with Tomcat (using AJP v1.3 protocol through TCP port 8009), can be downloaded
from Tomcat mother site @ tomcat.apache.org (⇒ Download ⇒ Tomcat Connectors ⇒ JK 1.2 ⇒
JK 1.2 Binary Releases ⇒ win32 ⇒ jk-1.2.25 ⇒ "mod_jk‐apache‐2.2.4.so").

Rename the downloaded module to "mod_jk.so" and move into directory "c:\apache\modules".

Step 2: Configure Apache


We need to configure the Apache HTTP Server to load and initialize the JK module.
Create a configuration file called "mod_jk.conf" as follows and place it in "c:\tomcat\conf":
# Load mod_jk module
# Update this path to match your modules location
LoadModule jk_module modules/mod_jk.so

# Where to find workers.properties


# Update this path to match your conf directory location
JkWorkersFile c:/tomcat/conf/workers.properties

# Where to put jk logs


# Update this path to match your logs directory location
JkLogFile c:/tomcat/logs/mod_jk.log

# Set the jk log level [debug/error/info]


JkLogLevel info

# Select the log format


JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"

# JkOptions indicate to send SSL KEY SIZE,


JkOptions +ForwardKeySize +ForwardURICompat ‐ForwardDirectories

# JkRequestLogFormat set the request format


JkRequestLogFormat "%w %V %T"

# Send everything for context /ws to worker ajp13


JkMount /ws ajp13
JkMount /ws/* ajp13

# Send everything for context /jsp‐examples to worker ajp13


JkMount /jsp‐examples ajp13
JkMount /jsp‐examples/* ajp13

# Send everything for context /servelts‐examples to worker ajp13


JkMount /servlets‐examples ajp13
JkMount /servlets‐examples/* ajp13

…ntu.edu.sg/…/apache_tomcat_howt… 2/4
8/11/2010 Howt to configure Apache 2 with To…
For each web context that is to be forwarded from Apache to Tomcat, include two JKMount
statements as shown. In the above configuration, Apache forwards all requests to web contexts
"/jsp‐examples", "/servlets‐examples", and "/ws" to Tomcat, via a "worker" called "ajp13".

Include the above configuration directives into the Apache's configuration by adding the following
include statement at the end of "c:\apache\conf\httpd.conf":
include c:/tomcat/conf/mod_jk.conf

Note: Unix's forward slash is used as the directory separator instead of backward slash (because
Apache was originally built for Unix). The include statement simply appends all the statements
from the file "c:\tomcat\conf\mod_jk.conf" into "httpd.conf". (You can of course add
those statements into "httpd.conf" directly.)

Next, observe that the configuration refers to a worker file called "workers.properties", and
forward certain requests to a JK worker called "ajp13". Create the "workers.properties" file
and place it in "c:\tomcat\conf" as follows:
# Define 1 real worker named ajp13
worker.list=ajp13

# Set properties for worker named ajp13 to use ajp13 protocol,


# and run on port 8009
worker.ajp13.type=ajp13
worker.ajp13.host=localhost
worker.ajp13.port=8009
worker.ajp13.lbfactor=50
worker.ajp13.cachesize=10
worker.ajp13.cache_timeout=600
worker.ajp13.socket_keepalive=1
worker.ajp13.socket_timeout=300

Note: The JKMount statements forward the requests to a worker called "ajp13", which is defined
in this "workers.properties".

Step 3: Configure Tomcat


The default configuration in Tomcat's "conf\server.xml" starts the AJP1.3 service via the
following configuration, on TCP port 8009 (remove the comments if these lines are commented).
<!‐‐ Define an AJP 1.3 Connector on port 8009 ‐‐>
<Connector port="8009" enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />

Step 4: Start the Apache with the JK module


c:\apache\bin> httpd ‐k install
c:\apache\bin> httpd ‐k start

Step 5: Start the Tomcat server


c:\tomcat\bin> startup

Observe that AJP1.3 service is initiated and the ajp13 worker is listening at port 8009.
....
Sep 26, 2006 1:16:50 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Sep 26, 2006 1:16:50 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/120 config=null
....

Step 6: Verify the Installation


…ntu.edu.sg/…/apache_tomcat_howt… 3/4
8/11/2010 Howt to configure Apache 2 with To…
Issue the following URLs to access the web context “/ws”, "/servlet‐examples", and "jsp‐
examples" that are defined in Tomcat (running in port 8080), but accessed via the Apache
(running in port 8000).
http://hostname:8080/ws Access Tomcat directly
http://hostname:8000/ws Access Tomcat via Apache
http://hostname:8000/servlets‐examples Try servlet examples via Apache
http://hostname:8000/jsp‐examples Try JSP examples via Apache

REFERENCES & RESOURCES


Apache-Tomcat Connectors @ http://tomcat.apache.org/download-connectors.cgi
Apache-Tomcat Connectors Documentation
Apache mother site @ www.apache.org
Tomcat mother site @ tomcat.apache.org

Latest version tested: Apache 2.2.4 / Tomcat 6.0.18 / JK 1.2.25


Last modified: April, 2009

Feedback, comments, corrections, and errata can be sent to Chua Hock-Chuan (ehchua@ntu.edu.sg) | HOME

…ntu.edu.sg/…/apache_tomcat_howt… 4/4

You might also like