Virtual Hosting by Name

Virtual Hosting by Name

Virtual hosting by name (as opposed to Virtual Hosting by IP) is a relatively new development in the HTTP standard. In this method, a variety of different domain names are associated with a single IP address. All the domain names are registered, and all requests are forwarded to the same IP. Once received, the server distinguishes the requests from one another by means of the HOST header, which is matched against any virtual hosts configured on the server.

Virtual hosting by name is a good system and undoubtedly has slowed the rate of IP address depletion somewhat. The catch is that only browsers which conform to the HTTP 1.1 standard supply the HOST header. If someone with an antique browser tries to access one of your name-based virtual hosts, you will have problems.

Configuring name-based virtual hosting is a three-step process.

         Create and register a new name for your virtual host.

         Make DNS aware that your existing IP address will henceforth also apply to the new virtual host name.

         Tell Apache how to handle requests directed to the virtual host.

DNS and Name Registration

The Domain Name Service (DNS) is sort of an Internet Yellow Pages. It is a distributed database of IP addresses and their associated domain names. Without DNS, or something like it, the Internet wouldn't have happened. When you use your browser to submit a request, the URL you typed in is useless until its IP address can be found in the DNS database.

With the ongoing expansion of the Internet, the supply of good domain names is dwindling. All of the possible three-letter domain names have been registered, so don't even bother. Most of the English words are similarly snagged. Requests for new domain names can be submitted at http://www.networksolutions.com.

Once you have a domain name you can live with, the worst is over. The odds are pretty good that you won't need to enter your own information in the DNS database. For most people, DNS registration is simply a matter of filling out a form and submitting it to the appropriate folks at some ISP.

DNS is a distributed database; that is, it is not found entirely (or even mostly) on a single server. Your request may be forwarded across multiple servers before a match is found and returned to you. As a side effect, it takes hours or days for a newly created URL to propagate across the DNS network.

Configuring Name-Based Virtual Hosting on Apache

This part is relatively painless. There are really only two steps although, to be fair, the second step can be sort of complicated:

1.       Use the NameVirtualHost directive to specify an IP address that will be used for virtual hosting.

2.       Use the VirtualHost directive pairs to set apart any directives that will apply only to your virtual Web site.

Enabling an IP for Name-Based Virtual Hosting

Place the NameVirtualHost directive in the httpd.conf configuration file to specify an IP address that will host virtual sites for example,

NameVirtualHost 192.168.1.1

alerts Apache to the possibility that requests may come in over the 192.168.1.22 IP address for servers other than the default. In order for Apache to make any use of this information, you must also specify virtual host-specific directives by using the VirtualHost delimiters.

Optionally, you may specify a port number in your NameVirtualHost directive by using

NameVirtualHost 192.168.1.1:80

Name-based virtual hosting only works with Web clients that conform to HTTP 1.1 or greater. The reason is that HTTP 1.1 provides the HOST directive, which specifies by name the host site (and port) from which the Web browser is requesting information. Without the HOST information, Apache would have no way of telling which one of the sites associated with a given IP address the client was requesting information from.

Enabling Virtual Hosting

The VirtualHost directive is a "container directive." It occurs in pairs that delimit the beginning and end of virtual host-specific directives. Continuing the preceding example, we have

<VirtualHost 192.168.1.1>

ServerName www.example1.org

DocumentRoot /some/other/directory

</VirtualHost>)

The main thing to note here is that the two directives contained inside the <VirtualHost> delimiters apply only to the virtual host specified by ServerName. The directives bracketed by <VirtualHost> override default directives for that IP. There is no numeric limit on directives encased in <VirtualHost> containers, but there are some limits on what makes sense. (See Figure 36-1.)

Figure 36-1. Directives NOT usable in Virtual Hosting.

graphics/36fig01.gif

IP Address or Domain Name?

If you look closely at the syntax for the commands discussed in this section (VirtualHost, BindAddress, etc.), you'll notice that many of them will allow you to specify a domain name, rather than an IP address for example,

<VirtualHost www.idiots_anonymous.org>

...blah, blah, blah...

</VirtualHost>

is technically OK and, in fact, more readable than using an IP address. Unfortunately, however, it is a performance nightmare. If you specify by name, you force Apache to look up the name in DNS every time it receives a query. Because DNS queries typically run across network connections, this one error could render a network connection unusably slow.

 



Linux Desk Reference
Linux Desk Reference (2nd Edition)
ISBN: 0130619892
EAN: 2147483647
Year: 2000
Pages: 174
Authors: Scott Hawkins

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