As a single server for a home or small business, you may not need to change a Web server much from the default for the one domain. However, when you look at the Internet, one machine publishes Web pages for many domains. This means that somewhere a machine hosts more than that for one domain. The term for this is virtual hosting, or multihomed hosting. In either case, you can configure the server to publish Web pages for more than one domain name. Domain names that are not associated with a real network or machine are considered virtual.
There are a couple of methods to make a virtual domain name available on a Web server. The first is to give each virtual domain an IP address in the domain name server (DNS) and assign the IP address to the Linux machine. (You can find more information about adding an IP address to a machine in Chapter 5.) For Internet use, these domain names and IP numbers must be registered and real. Making up names or IP numbers does not work. The other option is to assign the domains as conical names (CNAME) in the DNS.
In the case of real IP addresses, you need to add the information about the virtual server to the httpd.conf file. The following is an example of how to set the directives in the configuration file. These directives override the global directives set for the server when requests come in for this virtual domain.
<VirtualHost www.my_domain.com> ServerAdmin [email protected]_domain.com DocumentRoot /var/www/my_domain.com ServerName www.my_domain.com
ErrorLog /var/log/apache/my_domain.com-error.log TransferLog /var/log/apache/my_domain.com-access.log </VirtualHost>
However, when using one IP address for multiple domain names, you need to change one more line in the httpd.conf file. You must assign an IP address to the NameVirtualHost directive to identify the IP address to the Apache Web server. This line might look like this in your configuration file:
The server then uses a variable name submitted to the server by the client browser that indicates the host name. The specific host name is added to the VirtualHost directive section in the httpd.conf file. I prefer to use separate IP addresses because it is easier to set up and making changes later is just as easy. You can see from this example that the VirtualHost remains the same for each host name. The differences are in the conical names.
<VirtualHost 192.168.0.32> ServerAdmin [email protected]_domain.com DocumentRoot /var/www/my_domain/parts ServerName parts.my_domain.com
ServerAdmin [email protected]_other_domain.com
ErrorLog /var/log/apache/data.my_other_domain-error.log TransferLog /var/log/apache/data.my_other_domain-access.log </VirtualHost>
Was this article helpful?