Virtual hosting in Tomcat 7

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:

  1. Configure the domain names in the DNS server and reload the DNS services so that it can be replicated on the server. Following are the DNS records with the address and CNAME:

    Alias

    Record

    Domain

    webserver1.yxz.com

    A

    192.168.0.1

    www.xyz.com

    C

    webserver1.yxz.com

    www.xzy.com

    C

    webserver1.yxz.com

    www.abc.com

    C

    webserver1.yxz.com

  2. For implementing virtual hosting, you have to edit 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>
    
    Virtual hosting in Tomcat 7
  3. Once configuration is done, add the new DNS in the 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:
    Virtual hosting in Tomcat 7
  4. Save the configuration, followed by the recycle, and check the logs if any errors persist.
  5. Check the URLs www.xyz.com,www.xzy.com,www.abc.com in the browser.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.35.81