Apache VirtualHosts

The following tutorial will explain how to configure one Apache server to resolve for multiple domain names. We assume you already have install Apache on you Linux based server. Check your distribution for where the configuration files are stored. For this example I am using Ubuntu 12.04.1 LTS.

Make sure you have the DNS A records pointing to the external IP of your server.
We will setup the following domains:

  • example1.com
  • example2.ca

First step is to create separate directory’s for each website. Apaches default web folder is /var/www so we will make the folders in there.

cd /var/www
mkdir example1.com
mkdir example2.ca

Now that the directory’s are made you can upload the sites into each of them.

Next step is to make some configuration files for each of the websites. For that we are going to switch to the /etc/apache2/sites-enabled and create a new file. You can use another text editor if you wish.

cd /etc/apache2/sites-enabled
nano example1.com

Inside this file, you will want to insert the following config.

<VirtualHost *:80>
        ServerAdmin webmaster@example1.com
        ServerName example1.com
        ServerAlias www.example1.com

        DocumentRoot /var/www/example1.com

        <Directory /var/www/example1.com>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/example1.com-error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/example1.com-access_log.log common

</VirtualHost>

You could keep the logs in there default directory, but I like to know if one site has an issue that others are not. In this configuration we have not included CGI for security reasons.

The next configuration file is simple. Just need to replace example1.com with example2.ca.

<VirtualHost *:80>
        ServerAdmin webmaster@example2.ca
        ServerName example2.ca
        ServerAlias www.example2.ca

        DocumentRoot /var/www/example2.ca

        <Directory /var/www/example2.ca>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/example2.ca-error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/example2.ca-access_log.log common

</VirtualHost>

After you have created all your configs, it’s time to restart Apache.

sudo service apache2 reload

That is it. You have now configured multiple domains on Apache.

Similar Posts

  • I found out on the news that my grade 8 teacher (I had him for English 3 years ago) was charged and arested on Saturday for Sexual Exploitation and Luring a Child (internet). He was a good teacher but was always hyper and was funny but a lot of people found him… strange. For more…

  • |

    Birthday

    Well my birthday was on July 23 and my parents decided to get me a new mixing board. Well it arrived today and boy is it neat! 😀 It’s the new Alesis MultiMix 12 FireWire. It is a small version of the bigger recording studio mixing board. It does have firewire witch is already built…

  • Regular Life

    Well I havn’t posted in a while. I havn’t been busy just enjoying the nice weather and lots of school work. Our History class does a tutorial type of setup. Every one is in a group with a max number of people of 4. I have presented once already and got a 80% on the…

  • The Goals of 2022

    I started off 2020 on a great note and continued through the year. I used a daily checklist in Notion to make sure I accomplished something every day. Here is the single list of things. Learn something new Read 30 mins on Social Media Do House stuff A weird list, but here’s the reasoning behind…