|
Apache
- Virtual Hosts
Virtual hosts (sometimes virtual servers) refer to the capability of a
server with only one IP address to serve out several different websites.
When webhosting first started, this capability did not exist. Each domain
name had it's own IP address, and therefore each machine would have to
have multiple IP addresses, one for each domain that it hosted. This presented
problems because we were quickly running out of IP space to allocate to
people, as well as the fact that you can only have a maximum of 255 IP
addresses per ethernet card.
The solution to the problem was to create name based hosting (as opposed
to DNS based hosting, in which each domain name needed a valid reverse
DNS lookup). In name based hosting, multiple domains are pointed to the
same server or IP address. When requests are sent to the server, the packet
headers include the domain name being requested. The webserver interprets
this information and returns the correct website. This means that if you
do an nslookup (or equivilant) of a domain name, it will return the IP
address that it is pointed to (your server), but, if you then look up
the IP address, it will resolve to the name of your server (servername.netmar.com).
To set up virtual hosts, you'll have to edit your httpd.conf
file.
Essentially, all of your information for a virtual host is contained within
the <VirtualHost> and </VirtualHost> directives, similar to
an HTML tag.
There are many, many options that can be enabled or configured in the
VirtualHost entry, and we will only cover a simple virtual host here.
These are the essentials:
|
Config
Directive |
Explanation |
| <VirtualHost IP
Address:port> |
Begin vh. Port
is optional. Must have NameVirtualHost entry to mach "IP address" |
| ServerName
www.domain-name.com |
Associates
vh with the proper domain name |
| ServerAlias domain-name.com
domain2.com www.domain2.com |
list of additional
domains to be pointed to the same webspace (space-delimited). Usually
domain minus www |
| Document Root /home/user/www |
Path
to the webfiles for this vh. Most netmar systems use either /home/user/www
or /users/n/name/www. Must be absolute path, no trailing / |
| #Any comment |
Such as the
username associated with the vh, creation date, etc. |
| </VirtualHost> |
End vh entry |
If you have followed
this, you will be ready to create your virtual hosts. Here is a sample
one for you:
------- Sample Virtual
Host Entry ------------
<VirtualHost
192.168.1.1>
ServerName www.stuff-for-sale.com
ServerAlias stuff-for-sale.com stuff-for-rent.com www.stuff-for-rent.com
DocumentRoot /home/robert/www
# created Jan 19 2038-3:14:07am for username robert by will
</VirtualHost>
|
|