我是这样做的,我还为每个站点设置了不同的 SSL 证书(未显示)。我并不声称了解我所知道的一切,但这在几个安装中对我有用。每个实例都需要一个“jetty.xml”和一个“contexts.xml”文件。
假设码头安装在 /opt/Jetty...
启动两个引用两个版本 jetty.xml 的服务器实例(这可以在一个脚本中完成,如图所示,或在两个单独的启动脚本中完成)
start.sh...
cd /opt/Jetty
java -jar start.jar etc/jetty.xml etc/jetty2.xml
如果您的服务器有多个 ip,您可以使用 context.xml 文件在每个 jetty.xml 文件的连接器部分指定不同的 ip 或主机名。如果你只有一个 ip,那么你将使用上下文 xml 中的上下文路径设置来区分这两个实例。
在 jetty.xml 中,参考 ip 或主机,以及 目录以包含第一个实例的 context.xml:
<Call name="addConnector">
<Arg>
<New class="org.mortbay.jetty.nio.SelectChannelConnector">
<Set name="host">HOST OR IP FOR FIRST INSTANCE</Set>
<Set name="port"><SystemProperty name="jetty.port" default="80"/></Set>
<Set name="maxIdleTime">30000</Set>
<Set name="Acceptors">2</Set>
<Set name="statsOn">false</Set>
<Set name="confidentialPort">443</Set>
<Set name="lowResourcesConnections">5000</Set>
<Set name="lowResourcesMaxIdleTime">5000</Set>
</New>
</Arg>
</Call>
<Call name="addLifeCycle">
<Arg>
<New class="org.mortbay.jetty.deployer.ContextDeployer">
<Set name="contexts"><Ref id="Contexts"/></Set>
<Set name="configurationDir"><SystemProperty name="jetty.home" default="."/>/contexts/directory_for_FIRST_instance</Set>
<Set name="scanInterval">5</Set>
</New>
</Arg>
</Call>
在 jetty.xml 中,引用 ip 或主机,以及 目录以包含第二个实例的 context.xml:
<Call name="addConnector">
<Arg>
<New class="org.mortbay.jetty.nio.SelectChannelConnector">
<Set name="host">HOST OR IP FOR SECOND INSTANCE</Set>
<Set name="port"><SystemProperty name="jetty.port" default="80"/></Set>
<Set name="maxIdleTime">30000</Set>
<Set name="Acceptors">2</Set>
<Set name="statsOn">false</Set>
<Set name="confidentialPort">443</Set>
<Set name="lowResourcesConnections">5000</Set>
<Set name="lowResourcesMaxIdleTime">5000</Set>
</New>
</Arg>
</Call>
<Call name="addLifeCycle">
<Arg>
<New class="org.mortbay.jetty.deployer.ContextDeployer">
<Set name="contexts"><Ref id="Contexts"/></Set>
<Set name="configurationDir"><SystemProperty name="jetty.home" default="."/>/contexts/directory_for_SECOND_instance</Set>
<Set name="scanInterval">5</Set>
</New>
</Arg>
</Call>
如果定义如上所示,您可以通过触摸上下文 xml 文件重新加载 war 文件并重新启动应用程序。
将单独的上下文文件放在上下文目录的不同子目录中,每个子目录都指向同一个war文件,但具有不同的上下文路径和不同的虚拟主机。
/opt/Jetty/contexts/subdirectory_for_first_instance/context_first.xml
/opt/Jetty/contexts/subdirectory_for_second_instance/context_second.xml
在 context_first.xml - 你可以指定一个节点 (firstapp) 将始终链接到你的第一个应用程序
<Set name="contextPath">/firstapp</Set>
在 context_second.xml 中 - 您可以指定一个节点(firstapp),它将始终链接到您的第二个应用程序
<Set name="contextPath">/secondapp</Set>
(如果你想从同一个 ip 运行它们,以上是必要的(两个不同的上下文路径),我相信)
然后在单独的上下文文件中定义两个虚拟主机(必须映射浏览器正在使用的 url):
在 context_first.xml 中:
<Set name="virtualHosts">
<Array type="String">
<Item>www.my_first_app.com</Item>
</Array>
</Set>
在 context_second.xml 中
<Set name="virtualHosts">
<Array type="String">
<Item>www.my_second_app.com</Item>
</Array>
</Set>
注意:
如果您有两个 ip 或主机名,则可以将两个应用程序的上下文路径设置为“/”
如果你只有一个 ip,上下文路径将决定访问哪个应用程序
此外,重要的是,您可以将上下文参数发送到您的应用程序,以便它可以在必要时确定它是哪个实例。
向每个实例发送唯一值的上下文参数示例:
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- Custom context configuration -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<Set name="initParams">
<New class="java.util.HashMap">
<Put name="customer">Joes Fish Store</Put>
<Put name="ShowPanelNames">N</Put>
<Put name="FiscalYearStartMonth">10</Put>
<Put name="LiveEmail">Y</Put>
</New>
</Set>