Mapping Multiple Domains to Same Ip and Port but different applications on Tomcat

Assume you are running Tomcat on ip: and port: 80. Now you want that and both redirect to this ip and this port, but show different pages to the user. How can you do this with Tomcat?

When a request is made to a webpage, HTTP protocol will require that a host header is sent. So a sample HTTP request:
GET / HTTP/1.1
Host: otherhost:8081

In server.xml file of Tomcat you can have something like this:
<Host name="app1"  appBase="webapps-1" unpackWARs="true" autoDeploy="true" />
<Host name="app2"  appBase="webapps-2" unpackWARs="true" autoDeploy="true" />
where webapps are folders under where Tomcat is resides.
  • You can find more information on this here.
  • To test this in your local, you can modify the hosts file. Info can be found here.