Javatpoint Logo
Javatpoint Logo

Virtual Host Ubuntu

Introduction to Virtual Host

The Virtual Host term refers to the practice of executing multiple websites (like and on one device. Virtual hosts can be "IP-based", meaning that we have a distinct IP address for all websites, or "name-based", meaning that we have more than one name executing on all IP addresses. The concept that they are executing on a similar physical server isn't probable to the end user.

Apache server was one of the initial servers for supporting IP-based virtual hosts. The 1.1 and later versions of Apache support both name-based and IP-based virtual hosts. The latter virtual host variants are sometimes also known as non-IP or host-based virtual hosts.

A virtual host began with the aim of hosting multiple websites on one device in its starting days. It would also define sharing individual machine resources, like CPU and memory. The resources are utilized and shared in such a manner that maximum capability is archived.

The virtual host serves more aims than ever with the development of cloud computing, including solutions like virtual storage hosting, virtual server hosting, virtual application hosting, and sometimes entire/virtual data center hosting as well.

Virtual Host Working

There are several ways to set up a virtual host, and almost all ways are listed and explained below that are utilized today:

Virtual Host Ubuntu
  • IP-based
  • Name-based
  • Port-based


It is one of the easiest ways and could be utilized to use distinct directives based on the IP address. We use distinct IPs for all domains in the IP-based virtual hosting.

More than one IP will point to the unique domains of the server, and there would be only a single IP for a single server. This virtual hosting is gained by making more than one IP address for one server.


These types of virtual hosts are the most frequently and commonly used virtual hosting method used today. It will use one IP address for every domain on the provided server. The named-based virtual host will transfer a message to a server alerting about the domain name to which it's trying to connect when a browser is attempting to connect to a server. The server inspects the host configuration and hence returns the request along with the correct website if the domain name is given.


This type of virtual hosting is also the same as IP-based virtual hosting. The main difference between the two is rather than using the distinct IP address for all virtual hosts; we utilize ports in which the server is configured for responding to more than one website that is rely on the server port.

Virtual Hosting

Virtual hosting is a technique to host more than one domain name (with isolated handling of all names) on one server. It allows a server for sharing its resources, like processor cycles and memory, without needing every service given to use a similar hostname. The virtual hosting term is generally used in web server references, but the foundation does carry on to other internet services.

Shared web hosting is one of the extensively used applications. The amount for shared web hosting is less than an embedded web server due to various customers can be hosted on one server. Also, it is very basic for one entity to wish for using more than one name on a similar machine so that the names can reverse services provided instead of where those services appear to be hosted.

  • There are two primary types of virtual hosting: IP-based and name-based.
  • Name-based virtual hosting utilizes a hostname illustrated by the client.
  • It saves IP addresses the related administrative overhead.
  • However, the protocol being served should be supplied the hostname at the right point.
  • There are serious difficulties with name-based virtual hosting with TLS/SSL.
  • IP-based virtual hosting utilizes an isolated IP address for all hostnames, and it can be implemented with protocol but needs an embedded IP address per domain name provided.
  • Also, port-based virtual hosting is possible in the convention but is rarely utilized in practice due to it's unfamiliar to users.

IP-based and name-based virtual hosting can be merged: a server may contain more than one IP address and serve more than one name on a few or each of those IP addresses. It can be helpful when using TLS/SSL with wildcard certificates.

HTTP Server with Virtual Hosts

In this section, we will talk about the types of virtual hosts for i Web server on the HTTP Server. The virtual host concept permits multiple websites on one web server or system. The servers are characterized by their hostname. Guests are routed by IP address or hostname to the right virtual host to the website. Virtual hosting permits enterprises to share a single server to all have their domain names.

Virtual Host Types on an HTTP Server

On HTTP Server, there are three types of virtual Hosts:

Virtual Host Ubuntu
  • IP-based virtual host
    This type of virtual host needs a single IP address per hostname (website). This method works well but needs an embedded IP address for all virtual hosts.
  • Name-based virtual host
    It permits a single IP address to host multiple hostnames (websites). This method practically permits an endless number of servers, comfort of use and configuration, and needs no extra software or hardware. The primary drawback of this method is that the client should support the 1.1 version of HTTP that add the hostname details in the HTTP document requests. The current versions of almost all browsers support the 1.1 version of HTTP, but there are still previous browsers that support only the 1.0 version of HTTP.
  • Dynamic virtual host
    It dynamically permits us to add hostnames (websites) by adding content directories. This method is automatically based on entering the IP address and the host contents: header inside the pathname of the file used for satisfying the request.
  • The benefits of a dynamic virtual host are as follows:
    • A small configuration file so the server begins faster and utilizes less memory.
    • Including virtual hosts doesn't need the configuration to be modified or the server to be rebooted.
  • The drawback of a dynamic virtual host is that we can't have a distinct log file for all virtual hosts.

How to Set Up Virtual Host in Ubuntu?


On the Internet, all websites are hosted on a host (web server), connected to a network with any public IP address, and can handle requests for many web pages on one browser (client), like Internet Explorer, Firefox, or Chrome. If we need to host any website on our machine, we need to first install any web server. One of the best is the Apache server, which is an open-source application suitable for both Windows and Unix systems.

But what if we require to host more than one website on a similar server, regardless of having a single public IP address available? In this scenario, we need to set up virtual hosts to collaborate with distinct domains with a similar IP address on Apache.

We need to connect to our server by an SSH connection. We will jump to the next step and open the terminal window of our server in case of any local server.

Install Apache

Apache HTTP Server is a famous open-source server that provides widespread support, power, and flexibility to developers. The configuration of the Apache server doesn't take place in one monolithic file but rather by a modular design in which new files can be modified and added as required. We can make an individual domain or site called a virtual host in this modular design.

First, we need to update our system using the below command for installing Apache 2 from the official Ubuntu repositories:

Virtual Host Ubuntu

Then, install Apache 2 using the following command:

Virtual Host Ubuntu

Apache should be embedded among our firewall exceptions because it communicates externally. If using UFW, we will permit bidirectional communication between a client and Apache by entering the following command:

Apache should be already running. We can use the below command to check its status:

Virtual Host Ubuntu

After that, we will open our browser window and connect to our server IP address:

The welcome page of Apache will be shown if the web server was installed successfully.

A few issues may have appeared while installing Apache if it's not the case. In this scenario, remove Apache and continue with the new installation process. We can use the following command to uninstall Apache:

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA