What is Virtual Host?

Do you know just one IP address of a server, can we embed thousands of domains into it and run separately? That is the Virtual Host in Apache.

For Nginx, we call it Server Block, while for Apache users we call it Virtual Host. In a nutshell, Virtual Host is used to run multiple domains on one IP address of a Server/VPS. What is a Virtual Host?

What is Virtual Host?

VirtualHost is a defining of embedding multiple domain names into one IP address of a Server feature. And by custom installation, the server will know which domain is active in its folder. This is very meaningful because we do not need each domain an IP address but only one server can embed hundreds of domain names together.

How to install Virtual Host on Apache

Normally, Apache will have the default installation directory as “/etc/httpd/conf.d“, here configuration files ending in “.conf” will be included automatically. You just need to create a file with the file name that is easy to manage, then end as “.conf“, Apache will receive the file content.

You create a new file with the following content:

You need to pay attention to ServerAlias, this is where the domain name will work in any folder. You can custom as you like.

After creating the file and place it right, please restart Apache so that it receives the new installation file by command:

The commands depend on what operating system, CentOS, Ubuntu or CoreOS. In general, you can easily find the command of the correct operating system you need by Google searching.

Please note, if you move the file to the “/var/www/html” directory and get stuck unable to update or delete files from admin, you need to reset the permissions on Apache by running the following command:

Good luck !

Leave a Reply

Your email address will not be published. Required fields are marked *