Apache2/Name Based Virtual Hosts

This article is to help setup apache using Name Based Virtual Hosts, vhosts.

Installing Apache2
Emerge apache as root. Optionally, enable the ssl useflag if you would later upgrade your setup to server ssl protected content.

After it has completed emerging, you can add it to your bootscripts.

Configuring apache
Included from the main apache configuration file, is the directory. Here is where the configurations various virtual hosts are located.

The default configuration file is (and ) combined with.

Now to create add our first vhost, let's say www.example.com we first copy each of those file. There's two options how to do our splitting of hosts, we could have 1 file for each subdomain, creating, etc or put all the aliases into one main file per domain. In this tutorial we choose the later.

and edit the common file per vhost, in our 3 hosted example, www., webmail. and gallery. (all comments stripped for wiki-readabilty)

If you are running an SSL enabled site, all left is to set it up as described in Apache2/SSL and Name Based Virtual Hosts though the sample configs are a bit dated.

Thus for completeness sake the accompanying file.