Tomcat and multiple domains/applications

Solution 1:

From the beginning you have a single "Host" record in your conf/server.xml for localhost

<Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true">
      <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />
</Host>

Now you can add another "Host" records, for example

  <Host name="anotherclient.com"  appBase="anotherclient" unpackWARs="true" autoDeploy="true">

       <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="anotherclient_access_log." suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  </Host>

where name="anotherclient.com" is the new client's domain, and appBase="anotherclient" is its web application root directory name (where you deploy your war); it is relative to the tomcat home dir.

Changes will be accepted after tomcat is restarted.

Requests going to any other domains (not listed in server.xml) but pointing to IP address of your server will be passed to the default application, it is specified in the Engine element

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

Solution 2:

In its default configuration, Tomcat accepts requests for any hostname and sends them all to the "localhost" <Host> defined in conf/server.xml. If you haven't change that, then all you have to do is make sure that you have DNS records set up for both hostnames to point to your server.

If you want to have a different set of webapps for each hostname, then you'll have to define a second <Host> in conf/server.xml and use the appropriate hostname for it. (Note that you'll always have to have a "default" host where all requests go that don't match any of the explicitly-defined hosts).

You can read the documentation for <Host> here: http://tomcat.apache.org/tomcat-7.0-doc/config/host.html (That's for Tomcat 7.0.x. You didn't mention your version so I gave you a link to the latest version's documentation).

Solution 3:

Usually you have a tomcat (or other application server) on port different from 80 (like 8080 or 7001 or anything you want). After that you put a web server (like apache http server) on port 80 and configure one or many connector to point to different port on different application server with different address.

For Apache http + tomcat you can take a look at this link:

http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html