我有两个web应用程序大战STORE_ABC.war
和STORE_DEF.war
,在我的机器上运行一个JBoss服务器。我想在我的jboss中以相同的上下文路径部署这两个war,如下所示。
http://localhost:8080/home
For STORE_ABC.war
http://testsite1:8080/home
For STORE_DEF.war
jboss-web.xml
for STORE_ABC.war
and STORE_DEF.war
<jboss-web>
<context-root>/</context-root>
</jboss-web>
如何实现以上配置?
我在${jboss-home}serverdefaultdeployjbossweb-tomcat55.sar
文件夹内的server.xml
中添加了另一个主机vhost2
,如下所示:
<Server>
<Service name="jboss.web"
className="org.jboss.web.tomcat.tc5.StandardService">
<Connector port="8080" address="${jboss.bind.address}"
maxThreads="250" strategy="ms" maxHttpHeaderSize="8192"
emptySessionPath="true"
enableLookups="false" redirectPort="443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true"/>
<Connector protocol="HTTP/1.1" port="8081" address="${jboss.bind.address}"
redirectPort="${jboss.web.https.port}" />
<Connector port="8089" address="${jboss.bind.address}"
emptySessionPath="true" enableLookups="false" redirectPort="443"
protocol="AJP/1.3"/>
<Connector port="8445" address="${jboss.bind.address}"
maxThreads="100" strategy="ms" maxHttpHeaderSize="8192"
emptySessionPath="true"
scheme="https" secure="true" clientAuth="false"
keystoreFile="${jboss.server.home.dir}/conf/bookstore.keystore"
keystorePass="bookstore" sslProtocol = "TLS" allowTrace="true"/>
<Engine name="jboss.web" defaultHost="localhost">
<Realm className="org.jboss.web.tomcat.security.JBossSecurityMgrRealm"
certificatePrincipal="org.jboss.security.auth.certs.SubjectDNMapping"
/>
<Host name="localhost"
autoDeploy="false" deployOnStartup="false" deployXML="false">
</Host>
<Host name="vhost2" autoDeploy="false"
deployOnStartup="false" deployXML="false">
<Alias>testsite1</Alias>
<Valve className="org.apache.catalina.valves.AccessLogValve"
prefix="vhost2" suffix=".log" pattern="common"
directory="${jboss.server.home.dir}/log"/>
<DefaultContext cookies="true" crossContext="true" override="true"/>
</Host>
</Engine>
</Service>
</Server>
然后我在WEB-INF
文件夹内的STORE-DEF.war
中添加了一个新文件jboss-web.xml
,如下所示:
<jboss-web>
<context-root>/</context-root>
<virtual-host>testsite1</virtual-host>
</jboss-web>
现在我可以从URL http://localhost:8080/home
访问STORE-ABC.war
,从URL http://testsite1:8080/home
访问STORE-DEF.war
。
注意-不要忘记在hosts
文件中添加127.0.0.1 testsite1
。