WebSphere has gained significant market and mindshare in the Web application development space. Fortunately, there is a powerful, easy to use, and free alternative to WebSphere: Apache's Tomcat.
Tomcat is an open-source server and it is the reference implementation for Sun's servlet standard. Tomcat has proven itself as production quality and is used by many companies to access the iSeries. In either case, an often requested feature is the ability for one server to host multiple Web sites. The ability for a server to host multiple Web sites is called virtual hosting. This may be useful to application service providers or companies with multiple products or divisions. Since there is an abundant amount of information available on configuring virtual hosting with WebSphere, this tip will focus on how to use Tomcat for virtual hosting. Tomcat can be configured to operate as a plug-in to Apache's Web server or as a standalone server. Here, we'll demonstrate using Tomcat as a standalone server on a Windows system (though the process would be the same with Tomcat running on the iSeries).
1. Configure Tomcat
In our example scenario, we want to allow two different Web URLs to be serviced by one server: www.companyOne.com and www.companyTwo.com.
To accomplish this, we need to edit the "<Tomcat Install Directory>/conf/server.xml" and add the following:
<Host name="localhost" appBase="webapps" unpackWARs="true"
autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"></Host>
<Host name="companyTwo.com" appBase="webapps2"
unpackWARs="true" autoDeploy="true" xmlValidation="false"
xmlNamespaceAware="false">
<Alias>www.companyTwo.com</Alias>
</Host>
The first host entry is the default local host that is already present after you install Tomcat. Company One's URL will point to this host by default. The second host entry was added for Company Two's URL. Notice the second host has <alias> tags. Any number of alias tags can be added to handle variations in the URL. For instance, the second host entry would respond to requests for both 'companyTwo.com' and 'www.companyTwo.com'. The rest of the parameters are standard defaults with the appropriate changes to name and appBase.
Next, create a copy of the "webApps" directory and give it a different name (e.g. webapps2). This new directory will be the 'appBase' for Company Two.
2. Direct or Redirect DNS
DNS is an Internet service that directs URLs to a specific TCP address. For example, when you enter: www.ibm.com An Internet DNS server translates it to something like: 129.42.20.99. We must set our two Web site addresses to the same TCP address where our Tomcat is installed and operating. This step is normally done using a Web-based utility provided by your Domain register, such as Network Solutions.
3. Test
Once steps one and two are done, you can test by simply changing the root index.html in both webapps and webapps2 to some unique content and then accessing each URL.
Note: Browsers may cache data so you may need to clear cache or restart your browser to see results. DNS changes may also take several hours to propagate through the Internet.
That's it! As you can see, Tomcat is an easy to use application server for hosting multiple Web applications and even multiple Web sites.
---------------------------
About the authors: Paul Holm is an iSeries WebSphere and Java specialist at PlanetJ Corp. He worked for IBM-Rochester for over 10 years as a DB2/400 and Java/WebSphere developer. Matt Jensen is a Web software developer at PlanetJ Corp.