我的漫漫程序之旅

专注于JavaWeb开发
随笔 - 39, 文章 - 310, 评论 - 411, 引用 - 0
数据加载中……

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文件,内容如下:

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


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

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

 

# 加载 mod_jk 模块
LoadModule jk_module modules
/mod_jk-apache-2.2.3.so

# 指定 mod_jk 模块所需的配置文件 workers.properties 的位置
JkWorkersFile conf
/workers.properties

# 指定 mod_jk 模块的日志文件位置
JkLogFile logs
/mod_jk.log

# 指定 mod_jk 模块的日志级别
JkLogLevel info

# 指定 mod_jk 模块的日志格式
JkLogStampFormat "
[%a %b %d %H:%M:%S %Y]

# 发送所有请求上下文的请求给 admin
JkMount 
/* admin

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

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

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

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

看看最上面的一段配置就行了:

<Service name="jboss.web">

    
<!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL HTTP/1.1 Connector on port 8080
-->
  
    
<Connector port="8080" address="${jboss.bind.address}"    
         maxThreads
="250" maxHttpHeaderSize="8192"
         emptySessionPath
="true" protocol="HTTP/1.1"
         enableLookups
="false" redirectPort="8443" acceptCount="100"
         connectionTimeout
="20000" disableUploadTimeout="true" />  

    
<!-- Define a SSL HTTP/1.1 Connector on port 8443
         This connector uses the JSSE configuration, when using APR, the 
         connector should be using the OpenSSL style configuration
         described in the APR documentation 
-->
    
<!--
    <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />
    
-->

    
<!-- Define an AJP 1.3 Connector on port 8009 -->
    
<Connector port="8009" address="${jboss.bind.address}" protocol="AJP/1.3"
         emptySessionPath
="true" enableLookups="false" redirectPort="8443" />

      
<Engine name="jboss.web" defaultHost="localhost" >

         
<!-- The JAAS based authentication and authorization realm implementation
         that is compatible with the jboss 3.2.x realm implementation.
         - certificatePrincipal : the class name of the
         org.jboss.security.auth.certs.CertificatePrincipal impl
         used for mapping X509[] cert chains to a Princpal.
         - allRolesMode : how to handle an auth-constraint with a role-name=*,
         one of strict, authOnly, strictAuthOnly
           + strict = Use the strict servlet spec interpretation which requires
           that the user have one of the web-app/security-role/role-name
           + authOnly = Allow any authenticated user
           + strictAuthOnly = Allow any authenticated user only if there are no
           web-app/security-roles
         
-->

tomcat:
tomcat/conf/server.xml:

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


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

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

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

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

相关附件下载



posted on 2008-12-24 19:29 々上善若水々 阅读(5566) 评论(5)  编辑  收藏

评论

# re: Apache HTTPServer与JBoss/Tomcat的整合与请求分发  回复  更多评论   

好文章 谢谢
2008-12-25 08:25 | congdepeng@126.com

# re: Apache HTTPServer与JBoss/Tomcat的整合与请求分发  回复  更多评论   

不行呀,启了apache再启jboss,就报80端口被占用,反之亦然
2010-03-31 14:16 | stone5751

# re: Apache HTTPServer与JBoss/Tomcat的整合与请求分发  回复  更多评论   

@stone5751
请仔细看文章,上面已经把jboss的端口改成8080了
2010-05-27 16:07 | supercrsky

# re: Apache HTTPServer与JBoss/Tomcat的整合与请求分发  回复  更多评论   

我怎么不行啊,报:HTTP Status 404 - /
2013-06-21 16:33 | 开发吧

# re: Apache HTTPServer与JBoss/Tomcat的整合与请求分发  回复  更多评论   

可以的,访问错了,没加项目名称,所以访问不了。
2013-06-21 16:37 | 开发吧

只有注册用户登录后才能发表评论。


网站导航: