Tomcat - Apache Integration
Requirements:
- JDK 1.5
- Apache (apache_2.0.59-win32-x86-no_ssl.msi)
- Tomcat (apache-tomcat-5.5.20.exe)
- jakarta-tomcat-connectors ( mod_jk-1.2.14-apache-2.0.54.so)
Tomcat – Apache Integration (Using mod_jk connector) in Windows:
First install both the servers. Let apache be in port 80 and Tomcat in port 8080.
Create a workers.properties file with the following lines under the conf folder of Apache. This makes your apache listen to tomcat through the ajp13 class (ajp13 class sends the individual packet information using the Ajp13Packet class, and implements the communication between the server and the servlet container. It routes the tomcat’s servlet support methods to the correct packets for the webserver).
workers.tomcat_home=C:\Program Files\Apache Software Foundation\Tomcat 5.5
workers.java_home=C:\Program Files\Java\jdk1.5.0_03
ps=\
# Define worker 'workp'
worker.list=workp
# Set properties for worker 'workp' (ajp13)
worker.workp.type=ajp13
worker.workp.host=localhost
worker.workp.port=8009
worker. workp.cachesize=10
worker. workp.cache_timeout=600
worker. workp.socket_keepalive=1
worker. workp.reclycle_timeout=300
And copy the mod_jk.so (Mod_jk connector module file) file into the modules folder of Apache Home. The name of the connector file should be mod_jk.so only as per our code.
Now include the following code in the httpd.conf file in the conf folder of Apache. This loads and mounts the connector to interact with Tomcat.
LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel error
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
Alias /jsp-examples "C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/jsp-examples/"
AllowOverride None
Allow from all
Alias /servlets-examples "C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/servlets-examples/"
AllowOverride None
Allow from all
Alias /MyWebsite/ "C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/MyWebsite/"
AllowOverride None
Allow from all
deny from all
JkMount /jsp-examples/*.jsp workp
JkMount /servlets-examples/* workp
JkMount /MyWebsite/* workp
Here we have the Servlets-example, jsp-example and our own site MyWebsite Mounted. We can customize the alias and Directory tag to include other sites.The above finishes the configuration in Apache side.
Now add the following context paths in the server.xml file of Tomcat located under the conf folder. These context paths facilitate the deployment of the site. Place the code before closing the tag.
Each context path corresponds to a single folder in the webapps folder of tomcat. If your web application contains subfolders, then those folders also needs a corresponding context path.
For example: if MyWebsite contains another folder called folder1 then the context path for that must be as below:
And also add the corresponding Mount command in the httpd.conf in Apache
JkMount /MyWebsite/folder1/* workp
Now start the Tomcat server first and then Apache. Now try accessing the pages deployed in tomcat from apache’s port (80).
Example:
http://localhost/servlets-examples/
Or http://localhost/jsp-examples/
Or http://localhost/Mywebsite
Or http://localhost/MyWebsite/folder1
Likewise you can copy your site directly into the webapps folder of Tomcat and creating an alias and context as above would deploy your site.
Resources:



