使用同一端口运行多个java jetty实例(80)

使用同一端口运行多个java jetty实例(80),java,webserver,jetty,subdomain,virtualhost,Java,Webserver,Jetty,Subdomain,Virtualhost,例如: 我有一个主临时域 www.product.com 对于每个客户端,我需要将单独的子域映射到具有相同端口(80)但具有不同实例名称(不同的.wars文件)的同一服务器 (如果我错了,请纠正我)正如我所知,如果我启动jetty实例,每个实例将从单独的端口号开始 client1 war will start at port 3001 client2 war will start at port 3002 client3 war will start at port 3003 我的问题是如

例如:

我有一个主临时域

www.product.com
对于每个客户端,我需要将单独的子域映射到具有相同端口(80)但具有不同实例名称(不同的.wars文件)的同一服务器

(如果我错了,请纠正我)正如我所知,如果我启动jetty实例,每个实例将从单独的端口号开始

client1 war will start at port 3001
client2 war  will start at port 3002
client3 war will start at port 3003
我的问题是如何将端口为80的所有实例映射到相应的相同子域

如果我访问

www.client4.product.com
,我需要让jetty应用程序在3004端口运行

更新:


为了更好地理解我的体系结构,如果在端口3002上运行的client2 jetty实例由于运行时异常或内存泄漏或手动重新启动而处于关闭状态,则所有其他独立运行的jetty实例(类似于google appengine使用jetty的体系结构)

为此,请不要运行多个jetty实例。使用多个虚拟主机运行一个实例。为此,您可以如下配置jetty:

  <Configure class="org.eclipse.jetty.webapp.WebAppContext">
    <Set name="war"><SystemProperty name="jetty.home"/>/webapps/client1.war</Set>
    <Set name="contextPath">/</Set>
    <Set name="virtualHosts">
      <Array type="java.lang.String">
        <Item>www.client1.product.com</Item>      
      </Array>
    </Set>
</Configure>
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <Set name="war"><SystemProperty name="jetty.home"/>/webapps/client2.war</Set>
  <Set name="contextPath">/</Set>
  <Set name="virtualHosts">
    <Array type="java.lang.String">
      <Item>www.client2.product.com</Item>      
    </Array>
  </Set>
</Configure>

/webapps/client1.war
/
有关如何配置此项的详细信息,请参阅

或者,如果您真的想拥有多个Jetty实例,可以使用另一台服务器(如Apache)作为反向代理将其前置。然后,通过编辑httpd.conf,可以使用虚拟主机设置Apache:

<VirtualHost *:80>
     ServerName www.client1.product.com
     ProxyRequests off
     ProxyPass / http://someInternalHost:3001/
     ProxyPassReverse / http://someInternalHost:3001/
</VirtualHost>

<VirtualHost *:80>
     ServerName www.client2.product.com
     ProxyRequests off
     ProxyPass / http://someInternalHost:3001/
     ProxyPassReverse / http://someInternalHost:3001/
</VirtualHost>

服务器名www.client1.product.com
代理请求关闭
ProxyPass/http://someInternalHost:3001/
ProxyPassReverse/http://someInternalHost:3001/
服务器名www.client2.product.com
代理请求关闭
ProxyPass/http://someInternalHost:3001/
ProxyPassReverse/http://someInternalHost:3001/

有关更多信息,请参见。

根据您的建议,为所有客户端提供服务的单个jetty实例,如果jetty失败,或者我需要更新代码库或重新启动无法访问应用程序的所有客户端。对于代码重新部署问题,您可以使用jetty的热部署,因此无需重新启动。但是对于必须重新启动服务器的情况,除非在负载平衡器后面有两台服务器,否则就没有什么可做的了。您不能将两个jetty实例绑定到同一端口,因此如果您确实需要单独的jetty服务器,则需要将其与另一台服务器连接。您可以使用具有类似VirtualHost配置的Apache转发到正确的jetty服务器。为了更清楚,我更新了我的问题,你们能为我的架构发布jetty+Apache虚拟主机设置吗?这些配置是进入“jetty.xml”还是你们有其他建议?
<VirtualHost *:80>
     ServerName www.client1.product.com
     ProxyRequests off
     ProxyPass / http://someInternalHost:3001/
     ProxyPassReverse / http://someInternalHost:3001/
</VirtualHost>

<VirtualHost *:80>
     ServerName www.client2.product.com
     ProxyRequests off
     ProxyPass / http://someInternalHost:3001/
     ProxyPassReverse / http://someInternalHost:3001/
</VirtualHost>