Apache HTTPServer与JBoss/Tomcat的整合与请求分发

本文介绍如何通过Apache HTTP Server实现对JBoss/Tomcat应用服务器的请求转发。主要内容包括Apache HTTP Server的安装配置、mod_jk模块的使用、workers.properties文件的设置以及与JBoss/Tomcat的整合步骤。

Apache HTTPServer与JBoss/Tomcat的整合与请求分发

如果需要一台服务器来做转发请求的话,用 apache的HttpServer再好不过了。

假如一个客户请求服务器A,A并不直接处理客户端的请求,而是把请求转发到
服务器B。

来看一个具体怎么操作吧。

首先先下载一个apache-httpserver,这里用的是apache_2.2.3-win32-x86-no_ssl.msi,你可以在此
http://apache.mirror.phpchina.com/httpd/ 进行下载。或此看此文最后的附件也可。

安装就不用说了吧,安装完毕后。有时候启动服务会失败,我的第一次就失败了。端口被占用。
这时我们:

首先用netstat -ano 看是得到占用80端口的进程的PID,然后打开任务管理器,选择->查看->选择列,勾上PID(进程标识符),结束这个进程,再启动Apache就成功了.
可以在浏览器输入:http://localhost 出现 'it works' 说明就ok了.

服务启动成功后去下载:mod_jk-apache-2.2.3.so,本文附件中会提供。


1.进入apache的安装目录。找到modules把下载好的mod_jk-apache-2.2.3.so复制进去。
2.在conf目录建立一个workers.properties文件,内容如下:

None.gif # Define 1 real worker using ajp13
None.gifworker.list
= admin
None.gif#
Set properties for admin (ajp13)
None.gifworker.admin.type
= ajp13
None.gifworker.admin.host
= 127.0 . 0.1
None.gifworker.admin.port
= 8009
None.gifworker.admin.lbfactor
= 50
None.gif#worker.admin.cachesize
= 10
None.gif# worker.admin.cache_timeout
= 600
None.gifworker.admin.socket_keepalive
= 1
None.gif# worker.admin.recycle_timeout
= 300


其中host就是你要转发到的服务器IP,port是端口号。这里是用本机测试,所以只改端口号就行了。

3.打开conf目录下的httpd.conf文件,找到#LoadModule ssl_module modules/mod_ssl.so这一行。在
这一行下面加上:

None.gif # 加载 mod_jk 模块
None.gifLoadModule jk_module modules
/ mod_jk - apache - 2.2 . 3 .so
None.gif
None.gif# 指定 mod_jk 模块所需的配置文件 workers.properties 的位置
None.gifJkWorkersFile conf
/ workers.properties
None.gif
None.gif# 指定 mod_jk 模块的日志文件位置
None.gifJkLogFile logs
/ mod_jk. log
None.gif
None.gif# 指定 mod_jk 模块的日志级别
None.gifJkLogLevel info
None.gif
None.gif# 指定 mod_jk 模块的日志格式
None.gifJkLogStampFormat "
[ %a %b %d %H:%M:%S %Y ]
None.gif
None.gif# 发送所有请求上下文的请求给 admin
ExpandedBlockStart.gifContractedBlock.gifJkMount
/* admin

最后一个的admin就是第二步中的worker.list

None.gif < Service name ="jboss.web" >
None.gif
None.gif    
<!-- A "Connector" represents an endpoint by which requests are received
None.gif          and responses are returned. Documentation at :
None.gif          Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
None.gif          Java AJP   Connector: /docs/config/ajp.html
None.gif          APR (HTTP/AJP) Connector: /docs/apr.html
None.gif          Define a non-SSL HTTP/1.1 Connector on port 8080
-->
None.gif  
None.gif    
< Connector port ="8080" address ="${jboss.bind.address}"     
None.gif          maxThreads
="250" maxHttpHeaderSize ="8192"
None.gif          emptySessionPath
="true" protocol ="HTTP/1.1"
None.gif          enableLookups
="false" redirectPort ="8443" acceptCount ="100"
None.gif          connectionTimeout
="20000" disableUploadTimeout ="true" />   
None.gif
None.gif    
<!-- Define a SSL HTTP/1.1 Connector on port 8443
None.gif          This connector uses the JSSE configuration, when using APR, the
None.gif          connector should be using the OpenSSL style configuration
None.gif          described in the APR documentation
-->
None.gif    
<!--
None.gif     <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
None.gif                maxThreads="150" scheme="https" secure="true"
None.gif                clientAuth="false" sslProtocol="TLS" />
None.gif    
-->
None.gif
None.gif    
<!-- Define an AJP 1.3 Connector on port 8009 -->
None.gif    
< Connector port ="8009" address ="${jboss.bind.address}" protocol ="AJP/1.3"
None.gif          emptySessionPath
="true" enableLookups ="false" redirectPort ="8443" />
None.gif
None.gif      
< Engine name ="jboss.web" defaultHost ="localhost" >
None.gif
None.gif         
<!-- The JAAS based authentication and authorization realm implementation
None.gif          that is compatible with the jboss 3.2.x realm implementation.
None.gif          - certificatePrincipal : the class name of the
None.gif          org.jboss.security.auth.certs.CertificatePrincipal impl
None.gif          used for mapping X509[] cert chains to a Princpal.
None.gif          - allRolesMode : how to handle an auth-constraint with a role-name=*,
None.gif          one of strict, authOnly, strictAuthOnly
None.gif            + strict = Use the strict servlet spec interpretation which requires
None.gif            that the user have one of the web-app/security-role/role-name
None.gif            + authOnly = Allow any authenticated user
None.gif            + strictAuthOnly = Allow any authenticated user only if there are no
None.gif            web-app/security-roles
None.gif         
-->

tomcat:
tomcat/conf/server.xml:

None.gif <!-- Define an AJP 1.3 Connector on port 8009 -->
None.gif    
< Connector port ="8009" protocol ="AJP/1.3" redirectPort ="8443" />
None.gif


其中关于AJP的配置是一样的,这里可以更改你需要的端口,当然上面的apache也需要同时更改。

最后打浏览器测试一下吧:
http://localhost

显示的其实就是http://127.0.0.1:8009 ,如果你JBoss/Tomat下部署有测试工程。看一下吧。已经出现了。

好的,操作成功了。说明已经转发成功。

相关附件下载



好了apache的配置都搞定了,重启一下ok.

我们再来看一下jboss的配置:

找到:
jboss-4.2.3.GA\server\default\deploy\jboss-web.deployer\server.xml

看看最上面的一段配置就行了:
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值