Recent Changes - Search:
 Welcome to the Cisco Academy for Vision Impaired Linux Wiki.


edit SideBar


We covered virtual hosts and hosts files.

Virtual hosts

Virtual hosting is a mechanism that allows a single physical computer to serve multiple websites. This is useful especially in shared hosting situations where a single computer has multiple applications running on it. Our virtual hosting context is the Apache server since this is what we were using for pmwiki and for running dwww. There are 2 forms of virtual hosting namely ip based virtual hosting and name based virtual hosting. In ip based virtual hosting, the server serves websites depending on which ip address the client connects to. Therefore, each physical computer will have to have multiple IP addresses. Name based virtual hosting uses the name of the host to serve the relevant website. This host name is passed to the server in the location field in the HTML request that goes to the server.

In Apache, a virtual hosts file is used to configure the virtual server. This file, in its basic form is below.
<VirtualHost *> #This begins the virtual host definition. This directive defaults to port 80 but you can specify a port number here.

	ServerName #the name of the server
	DocumentRoot /hold/cavi/caviserver/webserver/cucat #Path to the directory where the pages to be served to clients are located
	ServerAlias #the text that the user types to get to this server. This has to be registered with your DNS server.

</VirtualHost> #end of virtual host definition

Apache since version 2 follows a moduler configuration, therefore you do not need to edit the httpd.conf file any longer. On ubuntu, you need to place the above file fragment in the /etc/apache2/sites-available directory. You can name the file anything you like. You then need to use the command a2ensite to add a sim link in the /etc/apache2/sites-enabled directory.

The hosts file: primitive DNS

Once we have defined our virtual host, we need to nbe able to navigate to it. If the server is running on an internal network, then it is probable that we do not have a local DNS server. It is possible to set one up but it is overkill specially if we just need to test a single virtual host. This is where the hosts file comes into play.

The hosts file maps IP addresses to names. On windows, the hosts file is found at the following location. C:\Windows\System32\drivers\etc. In this directory, there is a file without an extention called hosts. You edit this file using a text editor like notepad. The file contains help information. Scroll to the bottom of the file and add an entry like Save the file. Whenever you navigate to the computer will go to the IP address. The name in the hosts file has to match with the name you have defined in the ServerAlias directive. This will tell Apache which virtual host you want to navigate to.

Note: On ubuntu the hosts file is found in the /etc directory. Again, it is a file called hosts.


Virtual Host documentation - Apache HTTP Server Lecture 12 audio Apache server server on Ubuntu

Edit - History - Print - Recent Changes - Search
Page last modified on October 29, 2012, at 01:34 AM