ApacheTomcat的整合

作者:冉翔

 

环境:

windows2003

jdk1.5

Apache 2.0.53

tomcat5.5.9

 

相关软件下载地址:

apache 2.0.53

http://archive.apache.org/dist/httpd/binaries/win32/

tomcat5.5.9

http://archive.apache.org/dist/jakarta/tomcat-5/v5.5.9/bin/jakarta-tomcat-5.5.9.zip

jdk1.5

http://java.sun.com/j2se/1.5.0/download.jsp

mod_jk-1.2.12-apache-2.0.54.so

http://www.apache.org/dist/jakarta/tomcat-connectors/jk/binaries/win32/jk-1.2.12/mod_jk-1.2.12-apache-2.0.54.so

 

步骤,

 

前戏:先在D:/Java/tomcat/webapps/下面建立一个文件夹test

里面放上一个jsphtml文件,叫做index.jsptest.html好了:)

 

首先,将mod_jk-1.2.12-apache-2.0.54.so

放入apache/modules文件夹下面。

然后在apache/conf文件夹下,新建文件workers.properties

 

内容如下:

# 这现行根据安装目录做修改

workers.tomcat_home=D:/Java/tomcat

workers.java_home=C:/jdk1.5

ps=\

# worker.list=ajp13

worker.list=ajp12,ajp13

 

worker.ajp12.port=8007

worker.ajp12.host=localhost

worker.ajp12.type=ajp12

worker.ajp12.lbfactor=1

           

worker.ajp13.port=8009       

worker.ajp13.host=localhost    

worker.ajp13.type=ajp13

worker.ajp13.lbfactor=1

 

worker.loadbalancer.type=lb

 

worker.loadbalancer.balanced_workers=ajp12, ajp13

worker.inprocess.type=jni

worker.inprocess.class_path=$(workers.tomcat_home)$(ps)classes

worker.inprocess.class_path=$(workers.tomcat_home)$(ps)lib$(ps)jaxp.jar

 

worker.inprocess.class_path=$(workers.tomcat_home)$(ps)lib$(ps)parser.jar

 

worker.inprocess.class_path=$(workers.tomcat_home)$(ps)common$(ps)lib$(ps)jasper.jar

 

worker.inprocess.class_path=$(workers.tomcat_home)$(ps)common$(ps)lib$(ps)servlet.jar

 

worker.inprocess.class_path=$(workers.tomcat_home)$(ps)common$(ps)lib$(ps)webserver.jar

 

worker.inprocess.class_path=$(workers.java_home)$(ps)lib$(ps)tools.jar

 

worker.inprocess.cmd_line=-config

 

worker.inprocess.cmd_line=$(workers.tomcat_home)/conf/jni_server.xml

 

worker.inprocess.cmd_line=-home

 

worker.inprocess.cmd_line=$(workers.tomcat_home)

 

worker.inprocess.jvm_lib=$(workers.java_home)$(ps)jre$(ps)bin$(ps)classic$(ps)jvm.dll

 

 

worker.inprocess.stdout=$(workers.tomcat_home)$(ps)inprocess.stdout

 

worker.inprocess.stderr=$(workers.tomcat_home)$(ps)inprocess.stderr

 

worker.inprocess.sysprops=tomcat.home=$(workers.tomcat_home)

 

编辑apache/conf文件夹内的httpd.conf

添加如下字段:

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

LoadModule jk_module modules/mod_jk-1.2.12-apache-2.0.54.so

#禁止访问WEB_INFMETA_INF目录。

 <Directory ~ "/WEB-INF/">

     Order allow,deny

     Deny from all

    </Directory>

     <Directory ~ "/META-INF/">

     Order allow,deny

     Deny from all

    </Directory>

 

#添加映射,使可以使用http://localhost/test/来访问

Alias /test/ "D:/Java/tomcat/webapps/test/"

    <Directory "D:/Java/tomcat/webapps/test/">

        Options Indexes MultiViews

        AllowOverride None

        Order allow,deny

        Allow from all

        DirectoryIndex index.jsp

    </Directory>

#添加映射,使可以使用http://localhost/test来访问,注意最后没有那个/

Alias /test "D:/Java/tomcat/webapps/test/"

    <Directory "D:/Java/tomcat/webapps/test/">

        Options Indexes MultiViews

        AllowOverride None

        Order allow,deny

        Allow from all

        DirectoryIndex index.jsp

    </Directory>

 

#加载配置文件

JkWorkersFile "D:/Java/xampp/apache/conf/workers.properties"

#URL进行规则匹配

JkMount /test/ ajp13

JkMount /test/servlet/* ajp13

JkMount /test/*.jsp ajp13

JkMount /test/*.do ajp13

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

查看tomcat/conf/下的server.xml

添加如下字段,当然如果已经有了就不用添加了,或者有注释,去掉就可以了。

<Connector port="8009"

               enableLookups="false" redirectPort="8443" protocol="AJP/1.3" URIEncoding="GBK" />

 

至此启动tomcat,启动apache

访问

http://localhost,出现apache欢迎界面

http://localhost:8080,出现tomcat欢迎界面

http://localhost:8080/waityou,出现index.jsp的页面,去掉:8080,正常。

http://lcaolhost:8080/waityou/test.html,出现test.html的页面,去掉8080,正常。

 

阅读材料:

http://community.csdn.net/Expert/topic/3902/3902301.xml?temp=.441662

http://jakarta.apache.org/tomcat/connectors-doc/

Tomcat权威指南》英文版

 

感谢:PIGO。在QQ上对我进行热心的讲解和辅导。解除了我的很多疑问。教会了我很多东西。