Andrei Pall

Linux Software Engineering

Virtual Hosts In Tomcat

Apache Tomcat is an open-source Java Servlet Container developed by the Apache Software Foundation. Tomcat implements several Java EE specifications including Java Servlet, JavaServer Pages (JSP), Java EL, and WebSocket, and provides a “pure Java” HTTP web server environment in which Java code can run.

To create virtual host edit the tomcat-users.xml file from the conf Tomcat installation directory:

<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="andrei" password="password" roles="admin-gui,manager-gui,manager-script,manager-jmx,manager-status"/>

After that edit the TOMCAT_HOME/conf/server.xml config file and add a new virtual host:

  <Host name="outdoorduds.com"  
        appBase="outdoorapps"
        unpackWARs="true"
        autoDeploy="true">
    <Alias>www.outdoorduds.com</Alias>
  </Host>

And add the virtualhost to /etc/hosts file:

127.0.0.1       outdoorduds.com

Restart Tomcat if is running and deploy ROOT.war to the new appBase, TOMCAT_HOME/outdoorapps – now we have a ‘root context’ for the new domain name.