用apache配置多个tomcat webapp

时间:2021-04-16 15:04:53

The Apache HTTP Server Project is an effort to develop and maintain an open-source HTTP server for modern operating systems including UNIX and Windows NT.

Apache Tomcat is the servlet container that is used in the official Reference Implementation for the java Servlet and JavaServer Pages technologies.

apache2.2 和tomcat6到www.apache.org官方网站下载。

tomcat 5 版本以后通过ajp13连接器(之前ajp12)与apache相连,tomcat ajp监控端口默认为8009。

以tomcat6.0为例,需要以下步骤:

从从tomcat.apache.org下载 连接器

1    下载连接器文件:

url(for win32): http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.26/mod_jk-1.2.26-httpd-2.2.4.so

url(for linux):

http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/linux/jk-1.2.26/x86_64/mod_jk-1.2.26-httpd-2.2.6.so

2   将下载的so文件放置到apachDir/modules目录下

3   在apacheDir/conf目录下新增workers.properties文件,并添加如下内容:

ps=\

workers.tomcat_home=D:\devtool\apache-tomcat-6.0.14

workers.java_home=C:\java\jdk1.5.0_11

worker.list=worker1,worker2

worker.worker1.port=8009

worker.worker1.host=127.0.0.1

worker.worker1.type=ajp13

worker.worker2.port=8009

worker.worker2.host=127.0.0.1

worker.worker2.type=ajp13

该文件中定义了2个worker,对应2个web应用,这里只指向同一个tomcat,实际中可以指向不同的机器或不同的端口。

3   修改apache的配置文件conf/httpd.conf:

找到最后一个LoadModule ,在下面添加:

LoadModule jk_module modules/mod_jk-1.2.26-httpd-2.2.4.so

JkWorkersFile F:/Apache2.2/conf/workers2.proerties

JkLogFile jklog.log

# Set the jk log level [debug/error/info]

JkLogLevel info

# Select the timestamp log format

JkLogStampFormat “[%a %b %d %H:%M:%S %Y] “

# Send servlet for context /examples to worker named worker1

# JkMount /examples/servlet/* worker1

# Send JSPs  for context /examples to worker named worker1

#example webapp

JkMount  /examples/* worker1

#statistic webapp

JkMount  /statistic/* worker2

至此,设置结束,

重启apache,打开tomcat6

我们试验一下效果 :打开浏览器,地址栏输入:http://localhost/examples/