Hi folks,
Today I will discuss how to create a VirtualHost on Tomcat 8. For those who don’t know, Tomcat is a very popular open-source web server for hosting Java web applicationsm. Tomcat implements a bunch of Java EE specifications like Java Servlet, JavaServer Pages (JSP), Websocket and Java EL [1].
Let’s assume you installed Tomcat 8 in /usr/local/apache-tomcat-8.0.30. you want to add a virtual host sweetapp.com. Assume the project folder is at /usr/local/apache-tomcat-8.0.30/webapps/myapp
Open the file /usr/local/apache-tomcat-8.0.30/conf/server.xml
Then add the following lines:
<Host name="sweetapp.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Alias>www.mydomain.org</Alias>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="sweetapp_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<Context path="" docBase="/usr/local/apache-tomcat-8.0.30/webapps/myapp"
debug="0" reloadable="true"/>
</Host>
Save and close the file.
Then restart tomcat using the commands:
/usr/local/apache-tomcat-8.0.30/bin/shutdown.sh
/usr/local/apache-tomcat-8.0.30/bin/startup.sh
Sources
Apache Tomcat – Wikipedia, the free encyclopedia. https://en.wikipedia.org/wiki/Apache_Tomcat