Name-based virtual hosting on Apache is described on the Apache website as such:
With name-based virtual hosting, the server relies on the client to report the hostname as part of the HTTP headers. Using this technique, many different hosts can share the same IP address.
Therefore, more than one website can be hosted on one server through this method. On ubuntu, the configuration files are in /etc/apache2/sites-available. In that directory, you will find 000-default.conf. That is the default configuration, all requests will be sent to this configuration file until others have been set up.
To set up a virtual host, here example.com will be used, but you should replace it with your domain.com. Copy the default file:
cp 000-default.conf example.com.conf
The configuration file can have the following directives:
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
CustomLog /var/log/apache/logs/access.log combined
ServerAdmin is the contact details of website admin used for displaying with http error messages.
ServerName is the domain name of website.
ServerAlias is a secondary name of the website, usually will be www.domain.com
DocumentRoot is the root folder loaded when we browse a website.
ErrorLog is the file in where errors are directed
LogLevel. is the level of errors to be sent to the log
CustomLog is the file where access information is directed
Edit the file replacing example.com with your website domain name and appropriate directory for the website files.
Save the file and enable the site with the following Apache command:
sudo a2ensite example.com.conf
sudo service apache2 reload
A few more things that must be checked:
Your virtual host should be up and running! You can repeat this for other websites on the same server, with a different configuration file (using the same naming convention) and different directories under /var/www.