Virtual Hosts

Apache has the capability to serve more than one web site simultaneously. This is known as virtual hosting, and is an essential feature that allows individuals and hosting companies to use hardware efficiently to serve multiple web sites. To provide for this ability the web server configuration provides the <VirtualHost> container for a web administrator to maintain multiple domains/host names on one server.

Although the comments in the listen.conf file seem to suggest that this file is the place to define virtual hosts, the modular configuration setup on SUSE provides a directory /etc/apache2/vhosts.d to define virtual hosts. Each virtual host can be defined by a VirtualHost section in a separate file under this directory. Any file there with a name ending in .conf is read in to the main configuration. (However, if you use YaST for configuration, all the virtual hosts you set up are included in a file /etc/apache2/vhosts.d/yast2_vhosts.conf.)

The server must distinguish which virtual host a request for a web page is being addressed to. The two methods are to have multiple IP addresses configured on the server and distinguish requests on the basis of the IP address. This was the original method of defining virtual hosts, but it has been largely superseded by the method used here. That is, to distinguish the requests on the basis of the host name included in the HTTP request header. This is called name-based virtual hosting. Listing 16-1 shows a minimal name-based virtual host configuration. The imaginary site is being set up as a virtual host.

Was this article helpful?

0 0

Post a comment