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:
<VirtualHost *:80> ServerAdmin email@example.com ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/example.com/html ErrorLog /var/log/apache/logs/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache/logs/access.log combined </VirtualHost>
ServerAdminis the contact details of website admin used for displaying with http error messages.
ServerNameis the domain name of website.
ServerAliasis a secondary name of the website, usually will be www.domain.com
DocumentRootis the root folder loaded when we browse a website.
ErrorLogis the file in where errors are directed
LogLevel. is the level of errors to be sent to the log
CustomLogis 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.