Home > Hosting > Configure Apache with a Server Alias

Configure Apache with a Server Alias

March 10th, 2010

Notes on setting up apache for multiple web sites:

In the /etc/apache2 directory you have two directories:
- sites-available
- sites-enabled

The sites-available directory contains configuration files for each website.
The sites-available contains links to the configuration file in the sites-available directory.  It does not contain the file itself.

The mistake that is made at times is that *all* configs are placed in one file – default.

So, for a domain name like domain.com you would create a file called domain.com in the sites-available directory with the following:

NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/domain
ServerName www.domain.com
Server Alias domain.com
</VirtualHost>

you would do:  /ln -s /etc/apache2/sites-available/domain.com /etc/apache2/sites-enabled/domain.com

OR

a2ensite domain.com (from within the sites-available) directory.

finally:  /etc/init.d/apache2 reload

So, in a nutshell — create a file per domain name — use ServerAlias to cover www.domain.com and domain.com.

Andrew Hosting , , , , , ,

  1. No comments yet.
  1. No trackbacks yet.