We use cookies to improve our services and provide a better experience. By continuing to use this site, you agree with our Cookies Policy.

More than 400 step-by-step articles to guide you through online project development.
HomeTutorialsHosting ServicesCloud ServersAll Tutorials

Named Virtual Hosting

Virtual Host is the practice of operating more than a single website on a particular device. You can run two or more websites at a particular time, which saves the time and energy of the user delivering efficient results. There are different kinds of virtual host support like IP based virtual host, name based virtual host, file descriptor limits, virtual host examples for common setups, and dynamically configured mass virtual hosting. The name based virtual host is a way of providing multiple names operating on every single IP address. It does not matter that they are operating on the same server device.

Name based virtual host is commonly preferred

Apache is known for supporting the IP based virtual host initially when it was invented. Where the IP based virtual hosts uses the connected IP address to verify the right virtual host to operate, the name based virtual host is quite simple and needs just the configuration of DNS server to plot each host name to the right IP address. It then configures the Apache HTTP server to verify the various hostnames. In the latter host, the server fully depends on the user to submit the host name as a part of the HTTP headers. This enables various hosts to share a common IP address. The name based virtual hosting is commonly preferred by users due to its simplicity and uses, unless the device asks for IP based hosting.

Application of named virtual hosting

There is a series of processes that needs to be followed to utilize name based virtual hosting.

  • First, choose the IP address and port on the server that will readily accept request for the specific host. This can be done by using the “NameVirtualHost” command. When you select an IP address, it should be connected with a network interface on the server.
  • Now, you will need to create a slab for all the different hosts that you want to serve. The argument to the command should tally a mentioned “NameVirtualHost” command.
  • You will have to give a “ServerName” to each slab in order to allocate which host is served. Moreover, you will need a “DocumentRoot” instruction to show the location in the file system for the content of the host.
  • In case you are adding the virtual host to the present web server, you will have to create a slab for the current host. In that case, the “ServerName” and “DocumentRoot” integrated in this virtual host must be similar to the global “ServerName” and “DocumentRoot”. Record this virtual host in the configuration file for default host.
  • The adjustment of the configuration of the virtual host can be done by placing other commands inside the slab.
  • When the request displays, the server will firstly check if the IP address it is using is matching the “NameVirtualHost” or not. If it is compatible, then it will check on each slab with a similar IP address and will try to search one where the “ServerName” tallies with the asked hostname. If it is found, then the server will use configuration for that server and if no matches are found, then the initial listed virtual host that is similar to the IP address will be utilized.

The result of this procedure will be that the initial listed virtual host will be the default virtual host.

Rate this Tutorial:
No CommentsLeave a Comment