如果需要一臺(tái)服務(wù)器來做轉(zhuǎn)發(fā)請求的話,用 apache的HttpServer再好不過了。
假如一個(gè)客戶請求服務(wù)器A,A并不直接處理客戶端的請求,而是把請求轉(zhuǎn)發(fā)到
服務(wù)器B。
來看一個(gè)具體怎么操作吧。
首先先下載一個(gè)apache-httpserver,這里用的是apache_2.2.3-win32-x86-no_ssl.msi,你可以在此
http://apache.mirror.phpchina.com/httpd/ 進(jìn)行下載。或此看此文最后的附件也可。
安裝就不用說了吧,安裝完畢后。有時(shí)候啟動(dòng)服務(wù)會(huì)失敗,我的第一次就失敗了。端口被占用。
這時(shí)我們:
首先用netstat -ano 看是得到占用80端口的進(jìn)程的PID,然后打開任務(wù)管理器,選擇->查看->選擇列,勾上PID(進(jìn)程標(biāo)識(shí)符),結(jié)束這個(gè)進(jìn)程,再啟動(dòng)Apache就成功了.
可以在瀏覽器輸入:http://localhost 出現(xiàn) 'it works' 說明就ok了.
服務(wù)啟動(dòng)成功后去下載:mod_jk-apache-2.2.3.so,本文附件中會(huì)提供。
1.進(jìn)入apache的安裝目錄。找到modules把下載好的mod_jk-apache-2.2.3.so復(fù)制進(jìn)去。
2.在conf目錄建立一個(gè)workers.properties文件,內(nèi)容如下:
# 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就是你要轉(zhuǎn)發(fā)到的服務(wù)器IP,port是端口號(hào)。這里是用本機(jī)測試,所以只改端口號(hào)就行了。
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 模塊的日志級(jí)別
JkLogLevel info

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

# 發(fā)送所有請求上下文的請求給 admin

JkMount /* admin
最后一個(gè)的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" />

其中關(guān)于AJP的配置是一樣的,這里可以更改你需要的端口,當(dāng)然上面的apache也需要同時(shí)更改。
最后打?yàn)g覽器測試一下吧:
http://localhost
顯示的其實(shí)就是http://127.0.0.1:8009 ,如果你JBoss/Tomat下部署有測試工程。看一下吧。已經(jīng)出現(xiàn)了。
好的,操作成功了。說明已經(jīng)轉(zhuǎn)發(fā)成功。
相關(guān)附件下載