Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

running multiple java jetty instances with same port (80)

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)

like image 513
Sam Avatar asked Aug 29 '12 18:08

Sam


1 Answers

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.

like image 120
Chris Avatar answered Oct 12 '22 21:10

Chris