Home

Virtual Hosts

 


Virtual host refers to maintaining more than one server on a single machine; differentiated by their apparent host name. For example, both www.sambar.com and www.sambar.net reside at the same IP address, but appear as two independent web sites. The way this works is pretty simple. Multiple host names can point to the same IP address (i.e. www.sambar.com and www.sambar.net); when the browser connects to the host www.sambar.com, it connects to the IP address found via DNS and then passes in the request the header:
Host: www.sambar.com

This header is used by the server to find the specific configuration (virtual-host) to use to respond to the request. If no matching host is found, the default configuration found in the config/config.ini is used.

The Sambar Server supports virtual-hosts using the Host: directive passed by most newer Web browsers (and is a required feature of HTTP/1.1). This is the only mechanism used by the Sambar Server to support virtual hosting.

The benefits of using the Host: directive for virtual hosting is that it allows for a near-unlimited number of WWW servers to be supported by a single machine. A significant disadvantage is that the user's browser must support this part of the HTTP/1.1 protocol. Netscape Navigator 2.0 and later, as well as Microsoft's Internet Explorer 3.0 and later support this functionality.

Using non-IP Virtual Hosts

The configuration file vhosts.ini is used to configure virtual hosts for the Sambar Server. The following is a sample format for this file:

In addition, the default host directives are still found in the config.ini file. Should the host directive not match any of the hosts in the vhosts.ini file, or no vhosts.ini file exist (the default), the defaults from the config.ini file are used.

The Documents Directory directive may contain a path relative to the Sambar Server installation (shown) or an explicit path (i.e. c:/foobar/docs/ ).

Compatibility with Older Browsers

As mentioned above, many browsers do not send the required header for virtual hosts to work properly. One way to work around this is to have the default Sambar Server home page contain a map of all servers supported by the site and have all servers run within the same directory structure, allowing them to be cross-referenced even if the Host: directive is not sent.

Using the above example, the following would be the configuration of the config.ini file:

The vhosts.ini file would have the following configuration:

So when a browser that does not support virutal hosting comes to the site, the default.htm page is shown. This page has explicit links to SAMBAR.NET (home.htm) and SAMBAR.COM (index.htm). All documents for SAMBAR.NET are maintained in a directory structure within the docs directory as are the pages of SAMBAR.COM.

Implementation Limitations

There are some implementation limitations that users should be aware of:

Wild-card Matching

The vhost entry may contain wild-card characters to match multiple hosts (the star (*) character matches zero or more characters and the question-mark (?) character matches a single character). For example, to match all all hosts directed to the sambar.com domain, the following virtual host entry can be used:

DNS Resolution

Many users mistakenly assume that they can just pick a name like www.foo.com and put it in the vhosts.ini file and the server will become www.foo.com. This is not the case. The use of the virtual host feature requires that your system administrator configure multiple "host" names to the same IP address. For example, the host names www.sambar.com and www.sambar.net both point to the same IP address in the DNS tables maintained by the ISP used by Sambar Technologies.

Step-by-Step Virtual Host Configuration

Dave Crawford offers this step-by-step guide.

To run multiple hosts, you first need to have an internet Name Server (DNS server), that points them to your IP address. See the How-To on DNS servers for more info on that subject. This will deal strictly with the Sambar side of virtual hosting.

1) Decide where the docs are going to reside. For this example, we'll pretend you chose "E:\vhosts\"

2) Create two directories in E:\vhosts\, one called "thisname", one called "thatname".

3) Create two index.html files (saying "welcome to thisname.com" and "welcome to thatname.com"), and put them in their directories. You should now have the following on your harddrive:

e:\vhosts\thisname\index.html
and
e:\vhosts\thatname\index.html

4) Go to your Sambar admin page (and login)

5) Under "Servers", "WWW Server", click on "Virtual Hosts"

6) Enter the following data:

Virtual Host Namewww.thisname.com
Documents Directorye:\vhosts\thisname\
Default Pageindex.html
Log Fileaccess_thisname.log
(or leave it blank, and all will be logged to access.log)
Automatic Log mailto (enter the name of the admin person for thisname.com, or leave blank)
CGI Directory/cgi-bin/
WinCGI Directory/cgi-win/

Click on "Create New Virtual Host" button.

7) Repeat step (6) for thatname.com.

8) Restart your server.

9) In your browser enter www.thisname.com and you should see "welcome to thisname.com"

10) In your browser enter www.thatname.com and you should see "welcome to thatname.com"

Mail
Keep in mind that mail is different from virtual hosts. Setting up one will not set up the other, you have to do each individually. Heres what to do to get mail for multiple domains.

1) Log in to the Sambar Admin page.

2) Under Servers, Mail Server, select Configuration

3) Scroll down a bit, and find Local Domains

4) Enter a list of domain names you are receiving mail for, each one separated by a space. You can use wildcards if you need to. Heres what ours looks like:

Local Domains = *the-crawfords.* *CentralChiropractic.com *sweetgrassSoftware.com *explorer2260*.com *planetdog.ca *globalidi.net *globalidi.com *workright-online.com *tearsintherain.com *the-music-makers.com *ranmamusic.com *crawfordhistory.org *236scouts.org

The wildcard at the beginning of every domain allows sub-domains to receive mail too. Dont currently have any, but this way we dont have to make changes later.

You'll notice *the-crawfords.* doesnt have a .com ending, because we have the .com as well as .org. The wildcard allows mail for both to come in. Also, *explorer2260*.com allows mail for explorer2260.com, explorer2260dev.com, and explorer2260fan.com

Now, a problem will arise if you try and use the same account name under each domain. Mail sent to joe@domain1.com and mail sent to joe@domain2.com will both go to the mailbox joe

There is a way around this however! When setting up user accounts, set them up, not as joe, but as joe@domain1.com.

© 1998-2003 Sambar Technologies. All rights reserved. Terms of Use