准备工作
1. 安装java, apache, tomcat并设置好环境变量
2. 这里假设apache的安装目录为C:\Apache Group\Apache2,Tomcat的安装目录为C:\Apache Group\Tomcat 5.0
3. 下载mod_jk,放在任意目录下,这里我放在C:\apache\ConnApaTom下
做完准备工作后就开始二者的整合
1. 在apache的httpd.conf中加入以下内容
# Load mod_jk module
LoadModule jk_module ConnApaTom\mod_jk-1.2.8-apache-2.0.52.so
# Declare the module for <IfModule directive>
#AddModule mod_jk.c
# Where to find workers.properties
JkWorkersFile "C:\Apache Group\Apache2\ConnApaTom\workers.properties"
# Where to put jk logs
JkLogFile "C:\Apache Group\Apache2\ConnApaTom\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 servlet for context /examples to worker named worker1
JkMount /*/servlet/ worker1 #(1)
# Send JSPs for context /examples to worker named worker1
JkMount /*.jsp worker1 #(2)
JkUnMount /*.gif worker1
JkUnMount /*.jpg worker1
2. 注意上面的(1),(2)句,后面再说。这里先在C:\Apache Group\Apache2\ConnApaTom下建立一个文件workers.properties,内容如下
workers.tomcat_home="C:\Apache Group\Tomcat 5.0" #让mod_jk模块知道Tomcat
workers.java_home="C:\j2sdk1.4.2_08" #让mod_jk模块知道j2sdk
#
worker.list=worker1 #list of workers, more workers can be sperated by ','.When starting up, the web server plugin will instantiate the workers whose name appears in the worker.list property, these are also the workers to whom you can map requests.
# entries for worker1
worker.worker1.type=ajp13 #类型
worker.worker1.host=localhost #本机,若上面的Apache主机不为localhost,作相应修改
worker.worker1.port=8009 #工作端口,若没占用则不用修改
worker.worker1.lbfactor=1 #代理数,不用修改
3. 这里我的文件的根目录是D:\www,下面就通过修改apahe和tomcat的配置来实现在此目录下静态网页由apache来处理,动态网页由tomcat来处理:
为此首先要解决的是改变tomcat的根目录,在tomcat5.0以上的做法与以前的版本不同,写一个context片断,放在$CATALINA_HOME/conf/[enginename]/[hostname]/ 下,这里写在下文件www.xml,其内容为
<Context path="" docBase="D:\www"></Context>,这里就把tomcat的根目录改到D:\www。
对apache,其Documentroot也设为D:\www,(1)句JkMount /*.jsp worker1实现了将D:\www里的*.jsp就交由tomcat来处理
此时tomcat还不能对servlet进行处理,解决这个问题需要做三个方面的工作:
a. 在apache的http.conf里加入Alias语句,如在D:\www下建一个文件夹,servletPrg专门用来放servlet程序,
#Alias, so the servlets can be send to tomcat
Alias /servletProg/ "D:/www/servletProg/"
<Directory "D:/www/servletPro">
AllowOverride None
Options IncludesNoExec
AddOutputFilter Includes html
AddHandler type-map var
Order allow,deny
Allow from all
</Directory>
b. 在http.conf里加入:JkMount /*/servlet/* worker1,也就第(2)句
c. 在tomcat里再写一个context片断,
<Context path="/servletProg" docBase="D:\www\servletProg" reloadable="true" debug="0">
</Context>
这样,apache就可以把servletPrg里的servlet传给Tomcat了。
本文地址:http://com.8s8s.com/it/it10212.htm