Virtual host files are the files that specify the actual configuration of our virtual hosts and dictate how the Apache web server will respond to various domain requests.
Apache comes with a default virtual host file called 000-default.conf that we can use as a jumping off point.
We are going to copy it over to create a virtual host file for each of our domains.
We will start with one domain, configure it, copy it for our second domain, and then make the few further adjustments needed.
The default Ubuntu configuration requires that each virtual host file end in .conf.
Start by copying the file for the first domain:
Code: Select all
sudo su
cd /etc/apache2/sites-available/
cp 000-default.conf example.com.conf
edit the file to something like:
Code: Select all
<VirtualHost *:80>
ServerName mydomain.com
ServerName http://www.mydomain.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Enable the New Virtual Host Files
Code: Select all
cd ../sites-enabled
ln -s ../sites-available/example.com.conf .
Restart Apache
Code: Select all
sudo service apache2 restart