Tomcat 7 supports name-based virtual hosting. This approach is very useful in hosting multiple web applications on the single instance of Tomcat 7. It also gives more privileges to the administrator to separate the applications from each other and their access control restrictions. You cannot understand the real concept of virtual hosting unless you implement it. So why wait, let's do the real-life implementation for virtual hosting in Tomcat 7.
For example, if you want to host the previously mentioned sites on the web server, then the DNS will be configured in the following manner. Let us assume the web server name is webserver1.yxz.com
and is hosted on the IP 192.168.0.1. To implement the previous scenario, the following steps need to be performed:
Alias |
Record |
Domain |
---|---|---|
|
A |
192.168.0.1 |
|
C |
|
|
C |
|
|
C |
|
server.xml
, which is present in TOMCAT_HOME/conf
. The following entries need to be added for the virtual host, as shown in the following screenshot:<Host name="www.xyz.com" appBase="../Webapps"> <Context path="" docBase="."/> </Host>
hosts
file found in /etc/hosts
in Linux, and C:WindowsSystem32driversetc
in Windows. The following screenshot shows the addition of a different hostname and IP address in the hosts
file:18.225.35.81