How to configure Virtual Hosting in tomcat ?

Solution Verified - Updated -

Environment

  • EWS 1.x,2.x,3.x
  • Tomcat 5.x / 6.x/7.x/8.x

Issue

  • How to configure Virtual Hosting ( multi hosting )  in tomcat ?
  • Need a way of having Tomcat  'bind' to 2 unique IP addresses to 2 seperate hosts.

Resolution

Information on how to setup virtual hosts can be found at ,

Tomcat 6: http://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html

Tomcat 5: http://tomcat.apache.org/tomcat-5.5-doc/virtual-hosting-howto.html

Followiong is a server.xml exmaple configuration that makes the tomcat accessible as below:

http://x.x.x.x:8081
http://y.y.y.y:8081

<Server port="8005" shutdown="SHUTDOWN">
...
............
<Service name="Catalina">

<Connector port="8081" address="x.x.x.x" maxHttpHeaderSize="8192"
              maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
              enableLookups="false" redirectPort="8443" acceptCount="100"
              connectionTimeout="20000" disableUploadTimeout="true" />


<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>

     <Host name="localhost" appBase="webapps/public"
      unpackWARs="true" autoDeploy="true"
      xmlValidation="false" xmlNamespaceAware="false">
     </Host>

</Engine>
</Service>

<Service name="Catalina1">

<Connector port="8081" address="y.y.y.y" maxHttpHeaderSize="8192"
              maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
              enableLookups="false" redirectPort="8443" acceptCount="100"
              connectionTimeout="20000" disableUploadTimeout="true" />

<Engine name="Catalina1" defaultHost="localhost">

     <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>

     <Host name="localhost" appBase="webapps/private"
      unpackWARs="true" autoDeploy="true"
      xmlValidation="false" xmlNamespaceAware="false">
     </Host>

</Engine>
</Service>

</Server>

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments