
Works on Linux and Windows. The main difference is the folders locations. Tested on Fedora Core 2.
Environment:
Windows XP-2000-2003,
JDK 1.4.2_05 (Location: C:\jdk1.4.2_05)
Tomcat Server (Location: C:\server\tomcat)
Apache2 Server: (Location: C:\server\apache)
Module mod_jk2 : (Location: C:\server\apache\modules\mod_jk2.so)
Environment Variables:
%APACHE_HOME% = C:\server\apache
%CATALINA_HOME% = C:\server\tomcat
%JAVA_HOME% = C:\jdk1.4.2_05
The Linux environment variable must be mapped like that: $APACHE_HOME = /etc/httpd/ etc...
Additional Environment Variables:
%CLASSPATH% = C:\jdk1.4.2_05\lib
%JRE_HOME% = C:\jdk1.4.2_05\jre
configure server.xml host for your jsp pages like this:
<Server port="8005" shutdown="SHUTDOWN" debug="0">
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"
debug="0"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"
debug="0"/>
<!-- Global JNDI resources -->
<GlobalNamingResources>
<!-- Test entry for demonstration purposes -->
<Environment name="simpleValue" type="java.lang.Integer" value="30"/>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users -->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved">
</Resource>
<ResourceParams name="UserDatabase">
<parameter>
<name>factory</name>
<value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
</parameter>
<parameter>
<name>pathname</name>
<value>conf/tomcat-users.xml</value>
</parameter>
</ResourceParams>
</GlobalNamingResources>
<!-- Define the Tomcat Stand-Alone Service -->
<Service name="Apache Tomcat">
<!-- Define a Coyote/JK2 AJP 1.3 Connector on port 8009 -->
<Connector
port="8009"
maxThreads="150"
minSpareThreads="25"
maxSpareThreads="75"
enableLookups="false"
redirectPort="8443"
acceptCount="100"
debug="0"
connectionTimeout="20000"
disableUploadTimeout="true"
protocol="AJP/1.3" />
<!--You can also use IP here or the host that is default for you: -->
<Engine name="Catalina"
defaultHost="default-host.com"
debug="0">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="catalina_log."
suffix=".txt"
timestamp="true"/>
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
debug="0"
resourceName="UserDatabase"/>
<Realm className="org.apache.catalina.realm.MemoryRealm" />
<!--Your changes starting here:-->
<Host name="java.com"
debug="0"
appBase="C:\server\apache\htdocs\clients\java.com\public_html"
unpackWARs="true"
autoDeploy="true"
xmlValidation="false"
xmlNamespaceAware="false">
<Logger className="org.apache.catalina.logger.FileLogger"
directory="logs"
prefix="java.com_"
suffix=".log"
timestamp="true"/>
</Host>
</Engine>
</Service>
</Server>
Then you should configure your jk2.properties:
# handler.list=apr,request,channelJni
handler.list=apr,request,container,channelJni
channelSocket.port=8009
shm.file=C:/server/apache/logs/jk2.shm
channelJni.disabled = 0
apr.jniModeSo=C:/server/apache/modules/mod_jk2.so
apr.jniModeSo=inprocess
put your mod_jk2.so in %APACHE_HOME%/modules/
create in %APACHE_HOME%/conf/ file workers2.properties and configure it:
#define the shared memory file
[shm]
file=C:/server/apache/logs/jk2.shm
size=1048576
[lb:lb]
[status:]
info=Status worker, displays runtime information.
debug=0
disabled=0
# -- Channels -- #
[channel.socket:java.com:8009]
info=Forward to a local TCPIP socket.
port=8009
host=127.0.0.1
group=ajp13:java.com:8009
# -- Groups -- #
[ajp13:java.com:8009]
info=Ajp13 worker using a local channel.
channel=channel.socket:java.com:8009
# -- URIs -- #
[uri:/*.jsp]
group=ajp13:java.com:8009
[uri:/*.jspx]
group=ajp13:java.com:8009
[uri:/*.do]
group=ajp13:java.com:8009
# you can define some additional folder here:
[uri:/myapp/*]
group=ajp13:java.com:8009
# or just point at your root:
[uri:/*]
group=ajp13:java.com:8009
When you have multiple hosts you can configure the same locations by names (java.com in our case or replace it by your IP if you accessing to your server by IP):
# -- URIs -- #
[uri:java.com/*.jsp]
group=ajp13:java.com:8009
[uri:java.com/*.jspx]
group=ajp13:java.com:8009
[uri:java.com/*.do]
group=ajp13:java.com:8009
[uri:java.com/myapp/*]
group=ajp13:java.com:8009
[uri:java.com/*]
group=ajp13:java.com:8009
Accessing your host by IP should be configured in that way (parts of configuration that is different from previous):
...
# -- Channels -- #
[channel.socket:200.60.70.80:8009]
info=Forward to a local TCPIP socket.
port=8009
host=200.60.70.80
group=ajp13:200.60.70.80:8009
...
# -- Groups -- #
[ajp13:200.60.70.80:8009]
info=Ajp13 worker using a local channel.
channel=channel.socket:200.60.70.80:8009
...
# -- URIs -- #
[uri:200.60.70.80/*.jsp]
group=ajp13:200.60.70.80:8009
[uri:200.60.70.80/*.jspx]
group=ajp13:200.60.70.80:8009
[uri:200.60.70.80/*.do]
group=ajp13:200.60.70.80:8009
[uri:200.60.70.80/myapp/*]
group=ajp13:200.60.70.80:8009
You can deploy your workers2.properties wherever you want, but remember this location we will use it!
Configure your httpd.conf (Apache configuration file):
Here I give just parts of configuration to configure Apache with Tomcat ? so be sure you know how to configure the rest(. At least you should try to start Apache before you will reconfigure it to work with Tomcat.
#Loading mod_jk2 module.
#BTW, I recommend to put this part of config right after loading other modules.
LoadModule jk2_module "C:/server/apache/modules/mod_jk2.so"
<IfModule mod_jk2.c>
JkSet config.file C:/server/apache/conf/workers2.properties
</IfModule>
Then configure your Virtual Hosts:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot C:/server/apache/htdocs/clients/java.com/public_html/
ServerName java.com
ServerAlias *.java.com
DirectoryIndex index.html index.shtml index.jsp index.jspx
<Location "/*.jsp">
JkUriSet group ajp13:java.com:8009
</Location>
<Location "/*.jspx">
JkUriSet group ajp13:java.com:8009
</Location>
<Location "/*.do">
JkUriSet group ajp13:java.com:8009
</Location>
#You can skip root location but if you want you can configure it like #this:
<Location "/*">
JkUriSet group ajp13:java.com:8009
</Location>
ScriptAlias /cgi-bin/ C:/server/apache/htdocs/clients/java.com/cgi-bin/
ErrorLog C:/server/apache/htdocs/clients/java.com/error.log
CustomLog C:/server/apache/htdocs/clients/java.com/access.log common
</VirtualHost>
6) That part is the most interesting. Physically your site root folder is: C:/server/apache/htdocs/clients/java.com/
And if you think that your Tomcat will work with any JSP page deployed in this folder you're wrong. You should read the JSP page specification in this matter. You can find the links to RFCs that you need at in documentation for Tomcat.
Anyway, you've decided to move your 'webapps' location to C:/server/apache/htdocs/clients/java.com/
Three things to remember:
• If you decided to delete all content of the original 'webapps' folder (for security reasons), DO NOT delete 'balancer' folder. Or you need to change location of this folder, and configure the Tomcat to use it from this location, which is completely unnecessary, at least for me.
• In your root location (C:/server/apache/htdocs/clients/java.com/) create folder ROOT and put your index.jsp in this folder
• Now in this just created folder (now it's C:/server/apache/htdocs/clients/java.com/ROOT/), create folder WEB-INF. In this folder create file web.xml with this content:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>My Java Site</display-name>
<description>
My Java Site.
</description>
</web-app>
So, now you have two important locations to remember:
C:/server/apache/htdocs/clients/java.com/ROOT/,
C:/server/apache/htdocs/clients/java.com/ROOT/WEB-INF/
And two files:
C:/server/apache/htdocs/clients/java.com/ROOT/WEB-INF/web.xml
C:/server/apache/htdocs/clients/java.com/ROOT/index.jsp
First part Done. Enjoy!