Virtual Hosting Using External Web Servers


Resin is used in a variety of situations, from development to ISP-based hosting. In many situations, a single server can be used to host Web applications, which execute based on different IP addresses or domains. For example, you might have a company with a domain called company.com and a URL www.company.com that provides basic information. Using the same domain, you could also have the URL stats.company.com as a secure site for handling project statistics.

There is no need to have separate servers for these two different URLs existing on a single domain. In fact, you can take this example one step further and add an entirely new domain called ourcompany.com. This domain can exist on your server along with company.com. This type of hosting, called virtual hosting, allows a single server to host many different domains—a common practice with commercial hosting companies. In this chapter, we show you how to configure Resin specifically to handle basic virtual hosting as well as virtual hosting using external Web servers. We also explain how to provide individual virtual machines for each host.

Basic Virtual Hosting

We touched on the concept of supporting virtual hosting in Chapter 15, where we laid out all the elements available in the Resin configuration file. Of particular importance is the <host> element. This element allows you to specify an identifier as an attribute that the Resin server uses to determine if the current <host> element matches the domain within the URL being browsed. For example:

 <server>   <host id='www.company.com' /> </server> 

If a client attempts to browse www.company.com/servlet/store, the Resin server breaks off the domain part of the URL, www.company.com, and attempts to find a match within the <host> elements of its configuration file. If the domain isn't found in the configuration file, the server assumes it doesn't support that particular domain.

You can configure the Resin server to support numerous domains through its internal Web server by specifying more than one <host> element within the <server>. For example, this configuration file is designed to support both the www.company.com and www.ourcompany.com domains:

 <host id='www.company.com'>     <root-directory>f:/hosts/company_com</root-directory> </host> <host id='www.ourcompany.com'>     <root-directory>g:/hosts/ourcompany_com</root-directory> </host> 

Here we have two different <host> elements. The first one tells the server to match all requests with a domain of www.company.com and use the application directory called f:/hosts/company_com. With this host, browsing to the URL http://www.company.com/store.jsp causes the file store.jsp to be executed from the f:/hosts/company_com directory.

In the same manner, we defined a second host for the domain www.ourcompany.com using a completely different application directory, g:/hosts/ourcompany_com. A URL using the www.ourcompany.com domain finds a file in its specified application directory.

Just as you can use the <root-directory> attribute in each of the <host> elements, you can use all of the elements and attributes defined in Chapter 15 for the <hosts> element in each host definition. This allows each of the hosted domains to have individual configurations that don't interfere with the others.

You can imagine the headache of trying to maintain all the configuration information in a single file. However, as you may recall, you can use the <resin:include> element to include additional files into a single resin.conf file. For example:

 <resin>   <server>     <resin:include href='companycomhost.conf'/>     <resin:include href='ourcompanycomhost.conf'/>   </server> </resin> 

Instead of using a single resin.conf file with large <host> elements, you keep each of the <host> elements in separate files and include them in the primary configuration file.




Mastering Resin
Mastering Resin
ISBN: 0471431036
EAN: 2147483647
Year: 2002
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net