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

  • Part Time

    Well last week I changed my working hours. I now work from 12:00 – 5:00 Monday, Wednesday and Fridays. It’s nice because I get to sleep in now and still spend time with Jess. So far I’v made about $300. I’m looking into buying a laptop but I dunno how that’s going to work out….

  • Alesis MultiMix Hum

    The following information addresses how to repair a power supply issue with the Alesis MultiMix. I first noticed the problem about a 7 months ago. Symptoms are as follows: Clip & Sig LED are on solid (FX section) XLR Inputs hum The XLR input hum is the worst problem in my case. So after some Googling and…

  • Out come

    V-night went with no major problems. The only issue we had was sound levels at the back of the gym. A gym is the worest place to have a concert or show of any sorts. We ran the amps at max all of the show. The school is consider bigger speakers and another amp. 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…