CITA 310 Section 5 Virtual Hosts and Virtual Directories (Selected Topics from Textbook Chapter 6)
Virtual Hosts When Apache is configured for only one Web site or URL, it functions as a single main server. With virtual hosts, Apache functions as if it were a series of multiple, separate servers, each devoted to a URL.
Configuring Virtual Hosts You configure each virtual host by adding a VirtualHost container for it in the Apache configuration file. The opening VirtualHost directive specifies the IP address and an optional port number in which this virtual host should listen.
IP-Based Virtual Hosts Useful for flexibility because if each host has its own unique IP address, you can easily move the host to a different Web server. It is getting more expensive to get multiple IP addresses from an ISP.
Port-Based Virtual Hosts Associate each new Web site with a port above Because it requires a user to add the port number, it is not a popular method.
Name-Based Virtual Hosts Multiple host names can be associated with a single IP address. Getting a single IP address from your ISP is relatively inexpensive. You can host an almost unlimited number of hosts with a single IP address. It is the most common method of hosting.
IP-Based Virtual Host Example ServerName research.cita.com DocumentRoot htdocs/research
Port-Based Virtual Host Example Listen 8080 DocumentRoot htdocs/test
Name-Based Virtual Host Example NameVirtualHost :80 ServerName DocumentRoot htdocs ServerName test.cita.com DocumentRoot htdocs/test
ServerAlias Directive The ServerAlias directive sets the alternate names for a host, for use with name-based virtual hosts. The ServerAlias may include wildcards, if appropriate.
Configuring a Virtual Directory in Apache The following associates the virtual directory called testdir with the location of the directory Alias /testdir C:/testdir Then it configures the directory Order allow,deny <-- no space in between Allow from all
Redirection The Redirect directive maps an old URL into a new one by asking the client to re-fetch the resource at the new location. The old URL is a path beginning with a slash. A relative path is not allowed. Example: Redirect /google