running multiple java jetty instances with same port (80)

 ̄綄美尐妖づ 提交于 2019-12-06 01:48:28

问题


For Example:

I am having one primary temp domain

www.product.com

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

(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

What my question is how do i map all the instances with port 80 with appropriate identical sub domains

if i access

www.client4.product.com , i need to get jetty app running in port 3004

Update:

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)


回答1:


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.

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>

You can see the apache docs for more info.



来源:https://stackoverflow.com/questions/12184479/running-multiple-java-jetty-instances-with-same-port-80

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!