March 19, 2018 | 5:03 am
You are here:  / HOWTO / HOWTO: NameVirtualHost

HOWTO: NameVirtualHost

Every wonder how to set up multiple domain names on one IP address?

Here’s how:

Install Apache2.

In the /etc/apache2/sites-available directory, you’ll need to create a file for each virtual host that you want.
For our example, we will create 2 sites, and
First, you will want to create the directories for our sites:

# mkdir /home/
# mkdir /home/
# mkdir /home/
# mkdir /home/
# mkdir /home/
# mkdir /home/

Next, you will need to edit /etc/apache2/sites-available/default and add the following item to the top of the file:

<NameVirtualHost *>

Save the file and continue:
Open up your favorite editor (vi in my case) and punch in the following lines:

<VirtualHost *>

ServerAlias *
DocumentRoot /home/
ScriptAlias /cgi-bin/ /home/
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all

ErrorLog /home/
LogLevel warn
CustomLog /home/ combined

Save the file as /etc/apache2/sites-available/
Then copy that file to

# cp

Open the new file in your favorite editor and change all the instances of to
Now, all you need to do is create links in the /etc/apache2/sites-enabled directory to the config files you just created:

# ln -s /etc/apache2/sites-available/ /etc/apache2/sites-enabled/
# ln -s /etc/apache2/sites-available/ /etc/apache2/sites-enabled/

Reload Apache:

# /etc/init.d/apache2 reload

That is pretty much it.
Create index.html pages in each new home directory so you can see that they are pulling from the correct directories.