Just Enough Apache HTTP Server integration with Tomcat Web Container


17 Νοε 2013 (πριν από 4 χρόνια και 7 μήνες)

89 εμφανίσεις

Apache HTTP Server integration with Tomcat Web Container
Just Enough Apache HTTP Server integration with Tomcat Web
What is Apache HTTP Server?
A HTTP Server is a software that uses the Hypertext Transfer Protocol to make web
documents available to the internet. Apache is the robust, commercial-grade reference,
efficient, extensible implementation of the HTTP protocol. It is most popular HTTP
server and it is open source and free.
What is Tomcat Web Container?
Tomcat is a Java based Web Application container that was created to run Servlets and
JavaServer Pages (JSP) in Web applications. It was chosen by Sun as the offical
Reference Implementation.
(Note : Don't know what is Servlet/JSP yet? Do not worry. You can still go through this
tutorial for the integration of Apache and Tomcat. A subsequent tutorial will introduce
the concepts and development of Servlets/JSP)
As shown in the diagram below is the architecture we will like to achieve. A user will use
his browser to access the resources server by the Apache HTTP Server. Some resources
will be routed to the Tomcat Container for processing.
For example, if the user request for an URL
to Apache, the request will be
forwarded to Tomcat via the Connectors for processing. When the processing is
completed, the results will be sent from Tomcat to Apache and subsequently back to the

Tomcat Web Container
Apache HTTP Server
Why is the integration important?

Use Apache as a front end to connect to multiple instances of Tomcat. Thus, when one
Tomcat fails, the other can still continue serving the users.
Serving of Static pages, CGI, Perl, PHP
Apache supports the serving of the above contents and it does it very well. Thus if the
static pages, CGI, Perl or PHP need to be used with Java together, the integration
deployment will be very useful.
Your Web server can be placed in a demilitarized zone (between one firewall to the
external internet) while the application server (Tomcat in this case) and application data
stay protected behind a second firewall. This can achieve a highly secure environment.
What is required?
Apache HTTP Server
Tomcat Connectors
Tomcat-Apache plug-in that handles the communication between Tomcat and Apache.
All the above components are re already included in the OpenEnterpriseX distribution.
Simply take note of the directories they are installed in.
What is this tutorial about?
This tutorial aims to illustrate what are the required configurations for the integration. In
fact, when OpenEnterpriseX is installed, the integration has already been carried out by
the installer. Remember the Petstore application can be accessed via the Apache HTTP
In this tutorial, the focus will be on testing out the integration followed by steps to turn
off the integration. With the concept, it will be extremely easy to configure the integration
of Apache with your J2EE application in the future.
Step 1 – Start Tomcat
In this tutorial we are going to assume OpenEnterpriseX is installed to the default
. If OpenEnterpriseX is installed in other directory, simply
with the installed directory name.
Goto the OpenEnterpriseX directory. Tomcat is stored in the server sub directory. The
script to start Tomcat is stored in the bin directory.
Setup the paths to the Java sdd with the following two commands. This is of course
assuming that the Java SDK is installed in
directory. Replace this
directory with the directory that the Java SDK is installed.
(Optional : If you have problems take a look at the script in
C:\OpenEnterpriseX\v0.1\oex\scripts\startall.bat. The first two lines contains the full
settings for the following commands. This is setup by the OpenEnterpriseX installer)
Start Tomcat with the following command.
cd C:\OpenEnterpriseX\v0.1\server\jakarta-tomcat-5.0.19\bin
set JAVA_HOME=C:\j2sdk1.4.2_04
set PATH=C:\j2sdk1.4.2_04\bin;%PATH%
A new Dos window will be started to launch Tomcat. The following screenshot is how it
will look like when Tomcat has started completely.
Step 2 – Test out Tomcat in the Browser
Start your Browser (Internet Explorer or Mozilla or others).
Key in the URL as
Tomcat is started on the default port 8080. You can change this port number by going to
The following will appear in the browser if everything has been started successfully.
Scroll down the web page until you see the following. We are going to explore the Servlet
and JSP examples provided by Tomcat.
On the following page, look for a section similar to the screenshot below. Execute the
examples and explore the source.
on this
Step 3 – Start Apache HTTP Server
Goto the Apache HTTP Server directory. The executable to start Apache is in the bin
Start Apache by the following command.
The following is the screenshot for the output.
cd C:\OpenEnterpriseX\v0.1\server\apache-2.0.49\bin
Step 4 – Test out Apache in the Browser
Start your Browser (Internet Explorer or Mozilla or others).
Key in the URL as
Apache is started on the default port 80, which is what the browser will assume. Thus
there is no need to put the port 80 at the end of the URL string. You can change this port
number by going to C:\OpenEnterpriseX\v0.1\server\apache-2.0.49\conf\httpd.conf
Step 5 – Test out the integration
Start your Browser (Internet Explorer or Mozilla or others).
Key in the URL as
Notice it also goes to the Servlet examples page started in Tomcat.
Apache HTTP Server integration with Tomcat Web Container
We have already achieve the following architecture. The reason is that during installation
of OpenEnterpriseX, the integration of Apache and Tomcat has already been carried out.
This is done by plugging in the Tomcat Connectors and configuring the components.
The rest of this tutorial will provide insights on how to plug in the connectors and the
configuration setup.
Tomcat Web Container
Apache HTTP Server
Step 6 – Explore the Tomcat Connectors files
The Tomcat Connector can be downloaded separately from the Apache website.
It has already been integrated into Apache in OpenEnterpriseX.
Goto the Apache directory at C:\OpenEnterpriseX\v0.1\server\apache-2.0.49\
The following is a brief description of the files provided by the connectors
doc\mod_jk2 -
documentation files
modules\mod_jk2.so –
actual connector library
conf\mod_jk2.conf.sample -
sample configuration files for integration
conf\workers2.properties.sample -
sample configuration files for integration are in
OpenEnterpriseX provided the following file to setup the integration between Apache and
Tomcat :
The following are the contents of the file. The 9
and 10
lines are the setup for Apache
to forward requests that access the URL patterns /servlet-examples/* to Tomcat via port
Port 8009 is the default Tomcat port used for the integration. It can be configured in
The next two lines is used for the forwarding of requests from Apache to Tomcat if the
Petstore application is accessed. The last two lines is used for the forwarding of requests
from Apache to Tomcat if the Jboss console is accessed.
Thus in the future if there are any additional URL patterns in Tomcat to be integrated,
simply add to the above configuration file.
Locate the following line in the httpd.conf file (C:\OpenEnterpriseX\v0.1\server\apache-
LoadModule jk2_module modules/mod_jk2.so
The above line is used to inform Apache to make use of the Tomcat Connectors. It is
added by the OpenEnterpriseX installer. Comment or delete away this line if integration
between Apache and Tomcat is not required.
(Optional : Move the workers2.properties file to other directories and restart Apache.
Notice Apache can no longer forward requests to Tomcat. Undo what you have done at
the end of this tutorial.)