RedHat Linux 中 Apache HTTP Server 与 Tomcat 集成

本文主要介绍,通过Apache HTTP Server 访问部署在Tomcat下的应用

RedHat Linux Version:
Linux version 2.6.18-308.el5 (mockbuild@x86-007.build.bos.redhat.com) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-50)) #1 SMP Fri Jan 27 17:17:51 EST 2012

假设:
WEB Server Machine 的 IP 为:192.168.4.242 ( Apache HTTP Server 所在机器 ),Apache版本:2.2.26
APP Server Machine 的 IP 为:192.168.4.234 ( Tomcat 所在机器 ), Tomcat 版本:6

前提:
Apache HTTP Server 在RedHat Linux 已经安装,见另一博客:http://brofe.iteye.com/blog/1989128
JDK 在RedHat Linux 已经安装,见另一博客:http://brofe.iteye.com/blog/1988590
下载JK 模块,因为我使用的集成方式为JK:http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/netware/mod_jk-1.2.32-httpd-2.2.21-nw.zip

开始配置Apache HTTP Server

第一步:
将mod_jk-1.2.31-httpd-2.2.x.so 拷贝到Apache安装目录下的:/usr/local/httpd2.2/modules

第二步:
在 Apache安装目录 :/usr/local/httpd2.2/conf 目录中增加:workers.properties 文件
内容为:

Java代码 收藏代码
worker.list=worker1
worker.worker1.port=8009 # 此处的端口为,tomcat/conf/server.xml AJP 端口
worker.worker1.host=192.168.4.234 # 此处IP为:tomcat 所在机器的IP
worker.worker1.type=ajp13
worker.worker1.lbfactor=1


第三步:
在 Apache安装目录 :/usr/local/httpd2.2/conf 目录中增加:workers.conf 文件,内容为:

Java代码 收藏代码
NameVirtualHost *:80

<VirtualHost *:80>
ServerName www.xxxx.com
JkMount /* worker1
</VirtualHost>


第四步:
在 Apache安装目录 :/usr/local/httpd2.2/conf 下修改httpd.conf 文件,内容为:

Java代码 收藏代码
# 第56行增加以下三行
LoadModule jk_module modules/mod_jk-1.2.31-httpd-2.2.x.so
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
# 文件最后增加以下一行,内容为:
include /usr/local/httpd2.2/conf/workers.conf


第五步:修改Tomcat/conf/server.xml

Java代码 收藏代码
<Engine name="Catalina" defaultHost="localhost" jvmRoute="worker1">

<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->

<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>

<!-- -->
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />

</Host>

<!-- 自定义域名配置 -->
<Host name="www.xxxx.com" appBase="webapps">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="walmartros_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<Context path="" docBase="ros" debug="0" reloadable="true">
<Logger className="org.apache.catalina.logger.FileLogger" prefix="walmartros." suffix=".log" timestamp="true"/>
</Context>
</Host>
</Engine>


至此,通过JK方式将Apache与Tomcat集成配置已完成,重启Apache即可

测试:http://192.168.4.242/examples/index.html # 此处IP为Apache所在机器IP

以后为介绍Apache的集群配置
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值