使用相同的端口运行多个java jetty实例(80)
例如:
我有一个主要临时域名
www.product.com
对于我需要拥有的每个客户单独的子域映射到具有相同端口的相同服务器(80)但具有不同的实例名称(不同的.wars文件)
For each client i need to have separate sub domain mapped to same server with same port(80) but with different instance name (different .wars files)
www.client1.product.com
www.client2.product.com
www.clientn.product.com
(纠正我,如果我错了)我知道如果我启动jetty实例,每个将从单独的端口开始没有
(correct me if i am wrong) As i know if i start jetty instance , each will start at seperate port no's
client1 war will start at port 3001
client2 war will start at port 3002
client3 war will start at port 3003
我的问题是如何将所有具有端口80的实例与适当的相同子域映射
What my question is how do i map all the instances with port 80 with appropriate identical sub domains
如果我访问
www.client4.product.com
,我需要在3004端口运行jetty app
www.client4.product.com
, i need to get jetty app running in port 3004
为了更好地理解我的架构,如果在端口3002上运行的client2 jetty实例因运行时异常或内存泄漏而进入关闭状态或手动重启,所有其他独立运行的jetty实例(类似于google appengine背后的架构使用jetty)
for more understanding of my architecture , if client2 jetty instance running on port 3002 went to down state due to runtime exception or memory leakage or manual restart , all other jetty instances running independently (similar to architecture behind google appengine uses jetty)
要做到这一点,不要运行多个Jetty实例。使用多个VirtualHost运行一个实例。为此,您可以像这样配置jetty:
To do this, don't run multiple Jetty instances. Run one instance with multiple VirtualHosts. To do this, you can configure jetty like this:
<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>
检查此页面了解有关如何配置此内容的更多信息。
Check this page out for more information on how to configure this.
或者,如果你真的想拥有在多个Jetty实例中,您可以使用另一个像Apache作为反向代理的服务器。然后可以通过编辑httpd.conf来设置Apache虚拟主机:
Alternatively, if you really want to have multiple Jetty instances, you can front it with another server like Apache that acts as a reverse proxy. Apache can then be set up with virtual hosts by editing your httpd.conf:
<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>
你可以看到 apache docs 了解更多信息。
You can see the apache docs for more info.