What is a Virtual Host Server?

Virtual host servers allow multiple websites to share one device for maximum server resource utilization.

Name-based and IP-based virtual hosting are the two primary forms of virtual hosting. Name-based virtual hosting utilizes the hostname indicated by a client to reduce IP addresses and related administrative overhead costs, while it may be implemented through any protocol but requires one embedded IP address per domain served.

IP based

As with sharing telephone numbers, virtual hosts enable multiple domains or sites to share the same server. This type of hosting relies on matching the client hostname to a configuration on the server; upon receiving a request, when searching each VirtualHost> section by definition in order of definition the server searches for either ServerName or ServerAlias directives that match or it uses its default configuration if one cannot.

Sponsored

Example: If the virtual host is named “*”, it will capture requests on port 80 from all hosts, then choose which configuration to apply based on host name recognition or fallback to using IP-based virtual hosting as it provides the easiest method of creating virtual hosts.

Port based

Port-based virtual hosting enables multiple websites to share a single server more efficiently, but is more difficult to configure. A website uses the server’s ports to determine how it should respond to requests; each port corresponds with one host name or website – this arrangement is ideal for businesses that operate multiple domains but want them all on one server.

When a port based configuration receives requests from clients, its web server first checks if any hostname in the Host: header field matches any vhosts before redirecting that request back to its primary server for service.

Initializing process generates and inserts an internal IP hash table with IP addresses generated during initialization process, then when clients connect to an unspecified address and port, searching the hash table is performed to find its respective vhost; one with its port number specified first in VirtualHost directive serves requests.

Sponsored

Name based

Name-based virtual hosting has quickly become the go-to solution for virtual hosting today, enabling multiple domains to use one IP address. When web browsers attempt to connect, they send a message telling the server about which domain name they wish to connect under; upon checking its host configurations, the server returns with any correct website if found.

Name-based virtual hosting allows virtual hosts to be defined through a VirtualHost> directive, so when a browser makes a request the server checks all VirtualHost> arguments in their order of definition to select the most applicable match based on what was requested as host name.

Whenever a VirtualHost> definition doesn’t explicitly list its ServerName attribute, it will usually inherit one from its base server configuration. It is recommended to always explicitly list this information when creating name-based virtual hosts to prevent default vhosts from serving unwarranted requests.

Multi-domain

Virtual host servers allow multiple websites to be hosted on one web server instance by specifying in a config file their individual URLs and VPS IP addresses; when an HTTP request comes through for one of those websites it will be served from their Document Root location.

This tutorial will show you how to set up and test two Apache virtual hosts on a FreeBSD 12 server – an effective way of saving server costs and decreasing administration overhead.

To create a virtual host, begin by creating a VirtualHost > container. Within it, list all of the names that visitors may use to access your site such as company name and contact email. Next, define any directives you wish to alter such as ServerAdmin, DocumentRoot, ServerName, ErrorLog or CustomLog that will impact all requests to that virtual host.

About the Author: internet-admin