我有2个webapps部署在同一个JBoss / Jetty服务器。 在Jetty 5.1.14中,我有以下jetty-web.xmlconfiguration其中一个应用程序作为虚拟主机运行(在同一个端口上):
<Configure class="org.jboss.jetty.JBossWebApplicationContext"> <Call name="addVirtualHost"><Arg>app2.localhost.com</Arg></Call> </Configure>
这工作得很好。 不幸的是,它根本不适用于Jetty 6.1.17。 首先,“JBossWebApplicationContext”似乎现在被称为“JBossWebAppContext”,其次,我可以find的文档表明,我应该使用一个像这样的jetty-web.xml:
<Configure class="org.jboss.jetty.JBossWebAppContext"> <Set name="VirtualHosts"> <Array type="java.lang.String"> <Item>app2.localhost.com</Item> </Array> </Set> </Configure>
但是这也行不通。 这两个webapps部署没有错误,但是当我尝试访问虚拟主机名下的第二个应用程序时,它只是访问第一个应用程序。 这两个应用程序都在根上下文(这是不可协商的)。
我如何使虚拟主机工作?
我已经通过使用这个语法解决了这个问题:
<Configure class="org.jboss.jetty.JBossWebAppContext"> <Set name="VirtualHosts"> <Array type="java.lang.String"> <Item>host1.domain.com</Item> <Item>host2.domain.com</Item> </Array> </Set> </Configure>
问题原来是所有的Web应用程序需要定义的虚拟主机,如果他们在同一个容器中运行。 由于某种原因,部署一个带有虚拟主机的WAR和一个没有工作。 这在Jetty 5中工作得很好,所以我很困惑,但是为需要这个的所有应用程序定义虚拟主机文件不会是一个问题。
你可能会看到这是否适合你:
<New class="org.jboss.jetty.JBossWebAppContext"> <Arg><Ref id="Contexts"/></Arg> <Arg><SystemProperty name="jetty.home"/>/webapps/app1.war</Arg> <Arg>/</Arg> <Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</Set> <Set name="VirtualHosts"> <Array type="java.lang.String"> <Item>app1.localhost.com</Item> </Array> </Set> </New> <New class="org.jboss.jetty.JBossWebAppContext"> <Arg><Ref id="Contexts"/></Arg> <Arg><SystemProperty name="jetty.home"/>/webapps/app2.war</Arg> <Arg>/</Arg> <Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</Set> <Set name="VirtualHosts"> <Array type="java.lang.String"> <Item>app2.localhost.com</Item> </Array> </Set> </New>
(当然,根据需要调整文件名和path)