Virtual hosting refers to the practice of hosting multiple domain names (with separate handling for each name) on a single server. This allows one server to share its resources, such as memory and processor cycles, without requiring all services provided to use the same host name. The fact that they are running on the same physical server is not apparent to the end user.
There are two main types of virtual hosting, name-based and IP-based. Name-based virtual hosting uses the host name presented by the client. This saves IP addresses and the associated administrative overhead but the protocol being served must supply the host name at an appropriate point. In particular, there are significant difficulties using name-based virtual hosting with SSL/TLS. IP-based virtual hosting uses a separate IP address for each host name, and can be performed with any protocol but requires a dedicated IP address per domain name served. Port-based virtual hosting is also possible in principle but is rarely used in practice because it is unfriendly to users.
Name-based and IP-based virtual hosting can be combined: a server may have multiple IP addresses and serve multiple names on some or all of those IP addresses. This technique can be useful when using SSL/TLS with wildcard certificates. Apache was one of the first servers to support IP-based virtual hosts right out of the box.
Often abbreviated vhost, a virtual host is a provider of Web services that include server functions and Internet connection services. A virtual host is often used by companies or individuals that do not want to purchase and maintain their own Web servers and Internet connections. A limitation of using a virtual host is that the customer shares the Web services with all the other customers of the virtual host. If the virtual host is running multiple sites off the same server, then those sites will be competing for Web server resources.
The above statement, while true, doesn’t negate the fact that vhosts provide access to features and functionality that transform and render our sites in ways we could never have imagined. While there are some very obvious reasons to go the route of virtual hosting, cost prohibitive, let’s examine the plain and simple benefits gained from running a vhost web server:
- Serve multiple domains or subdomains from a single server.
- Apply site specific module-based features independently.
- Server performance tuning and configuration optimization benefits non-exclusive.
- “One server fits all” capabilities and approach to launching a wide array of sites.
- Consolidate server resources and minimize administration overhead.
- Vhosts can be deployed within a co-location or dedicated server.
Here’s an example of how you would set-up a subdomain scenario on your Apache web server where you have a “triple-w” site and separate “blogging” site.
DocumentRoot “C:/Program Files/Apache Software Foundation/Apache24/htdocs/virtualhosts/moorescode/www/”
<Directory “C:/Program Files/Apache Software Foundation/Apache24/htdocs/virtualhosts/moorescode/www/”>
DocumentRoot “C:/Program Files/Apache Software Foundation/Apache24/htdocs/virtualhosts/moorescode/blog/”
<Directory “C:/Program Files/Apache Software Foundation/Apache24/htdocs/virtualhosts/moorescode/blog/”>
<VirtualHost> and </VirtualHost> are used to enclose a group of directives that will apply only to a particular virtual host. Any directive that is allowed in a virtual host context may be used. When the server receives a request for a document on a particular virtual host, it uses the configuration directives enclosed in the <VirtualHost> section.
If you’re interested to see just how crazy/awesome you can get with the <VirtualHost> configuration directives stay tuned. In the meantime, let us know if you have any questions or specific hosting requirements, we can handle virtually any hosting need, well that is our forte!