by Void Main » Sat Mar 13, 2004 7:40 am
Virtual hosts are a way for you to have more than one web site on one machine. It gives the appearance of having multiple machines (virtual mahines, or virtual hosts). For example, say you have the DNS host names doogee.kicks-assk.net and homer.is-a-geek.net and they both point to your server's IP address. Using virtual host definitions in your apache configuration you can have a different web site for each name. Apache detects what name the user used in the URL in their browser to get to your server and if they used "homer.is-a-geek.net" then apache would use the settings for the homer.is-a-geek.net virtual host.
You can use almost any apache setting within the virtual host definition so you can tailor each web site individually. For instance, you would use a different DocumentRoot directory for each virtual host if you wanted a different web site for each name. You might want separate logs for each vhost. You might want different rewrite rules an other customizations. All of your apache settings you want applied to that virtual host go in that virtual host's definition in the apache config.
There are actually two types of virtual hosts in Apache. There are name based virtual hosts and IP based virtual hosts. You need to use the name based version (as I do on my home system). I would say name based is the most common. IP based virtual hosts require you to have more than one static IP address at your disposal. You would have 1 or more network interfaces in your server with more than 1 IP address assigned to the interface(s). Each virtual host would be bound to it's own IP address on the server for IP based virtual host configuration.