Sample configs?

Madison Kelly linux-5ZoueyuiTZhBDgjK7y7TUQ at public.gmane.org
Tue Nov 6 04:48:48 UTC 2007


William O'Higgins Witteman wrote:
> I'm looking for some sample configurations for apache2 and postfix.
> Specifically, I want to support several domains and subdomains in
> apache2, and several domains in postfix, all from the same IP.
> 
> I have followed the documentation, but I have not found any success
> actually getting it right, and I thought I might have better luck with
> an example or two.  Thanks.

What distro? Redhat-based distros and Debian-based distro (possibly 
others still) have quite different ways of setting up Apache2. Also, how 
do you plan to run Postfix? Using shell accounts to authenticate against 
or by using a SQL DB backend of some sort?

I use both Apache2 and Postfix+PostgreSQL+Dovecot for several domains 
under Debian. It was tricky to get going and I attribute at least a 
couple of my gray hairs to the task. So don't feel bad. :)

For starters, here is a great how-to on setting up Postfix using a MySQL 
backend for authentication. I used it as the template for my setup, 
though I wanted to use PostgreSQL as well as the same DB for many other 
tasks, so I broke from their steps fairly early on. I suspect though 
that you won't have a problem.

http://workaround.org/articles/ispmail-sarge/index.shtml.en

As for Apache2, assuming you are on a Debian-based distro, you need to 
setup a couple things. First up, you need to add:

Servername hostname.domain.com

To '/etc/apache2/apache.conf' (otherwise it will still work, but give 
you "unable to reliably determine host name" (or something) errors 
whenever you (re)start the daemon.

Now you need to decide where you are going to keep your website files. 
Personally, I use the directory structure:

/var/www/<full.domain.name>/html	<- normal HTML files
/var/www/<full.domain.name>/cgi-bin	<- Scripts
/var/www/<full.domain.name>/logs	<- log files for this domain

The rest of the config is done in '/etc/apache2/sites-available'. In 
here, you will start with a 'default' file. This is the "Virtual Host 
Container" (term for each virtual host file) that will match when 
someone hits your machine using the raw IP or a domain name that doesn't 
match any of the VHC. It is a good idea to put a place-holder here (ie: 
see mine here -> http://192.139.81.119).

The default VHC for me points to '/var/www/default/[html|logs|cgi-bin]'. 
Here is it's VHC (note the 'NameVirtualHost *' at the top!) unedited:

-=-=-=-=-=-
NameVirtualHost *
<VirtualHost *>
         ServerAdmin sysadmin-UqHW2wehKNmfJOJzLBvvIA at public.gmane.org
         Servername cluster.nouvelocity.com

         DocumentRoot /var/www/default/html/
         <Directory />
                 Options FollowSymLinks
                 AllowOverride None
         </Directory>
         <Directory /var/www/default/html/>
                 Options Indexes FollowSymLinks MultiViews
                 AllowOverride None
                 Order allow,deny
                 allow from all
         </Directory>

         ScriptAlias /cgi-bin/ /var/www/default/cgi-bin/
         <Directory "/var/www/default/cgi-bin">
                 AllowOverride None
                 Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
                 Order allow,deny
                 Allow from all
         </Directory>

         ErrorLog /var/www/default/logs/default-error.log

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

         CustomLog /var/www/default/logs/default-access.log combined
         ServerSignature On
</VirtualHost>
-=-=-=-=-=-

Now for each real domain you will want to create a copy of 'default' to 
a file called 'domain.com'. It doesn't so much matter what the name of 
the file is, but naming it to match the domain it contains the config 
for makes the most sense. So for my test domain 'feneon.com', I would:

host:/etc/apache2/sites-available# cp default feneon.com

Then edit '/etc/apache2/sites-available/feneon.com' to this (note the 
LACK of 'NameVirtualHost *'!):

-=-=-=-=-=-
<VirtualHost *>
         ServerAdmin sysadmin-UqHW2wehKNmfJOJzLBvvIA at public.gmane.org

         ServerName feneon.com
         ServerAlias www.feneon.com
         ServerAlias ftp.feneon.com

         DirectoryIndex index.shtml index.html

         DocumentRoot /var/www/feneon.com/html/
         <Directory /var/www/feneon.com/html>
                 Options +Includes Indexes FollowSymLinks MultiViews
                 AllowOverride Options
                 Order allow,deny
                 allow from all
         </Directory>

         ScriptAlias /cgi-bin/ /var/www/feneon.com/cgi-bin/
         <Directory "/var/www/feneon.com/cgi-bin">
                 AllowOverride None
                 Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
                 Order allow,deny
                 Allow from all
         </Directory>

         ErrorLog /var/www/feneon.com/logs/error.log

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

         CustomLog /var/www/feneon.com/logs/access.log combined
         ServerSignature On
</VirtualHost>
-=-=-=-=-=-

Because I want this one VHC to match not just 'feneon.com', but also 
'www.feneon.com' and 'ftp.feneon.com' I use the 'ServerAlias' directive. 
If you are setting up a VHC for a subdomain (ie: forums.feneon.com) you 
would only use the 'ServerName forums.feneon.com' directive. Also note 
the 'DirectoryIndex index.shtml index.html' directive! This is a 
space-separated list of file names to look for (in the order they 
appear) when a user calls a page without specifying a file name. So, if 
you are using PHP and your index file is 'index.php', change or add it here.

Lastly, now that you have your VHC files ready, you need to symlink them 
into the '/etc/apache2/sites-enabled' directory. generally each symlink 
name is preceded with a digit, though I don't think this is required. 
Let's pretend it is though. :) So then;

host:/etc/apache2/sites-available# ln -s ../sites-available/default 
./000-default
host:/etc/apache2/sites-available# ln -s ../sites-available/feneon.com 
./001-feneon.com
host:/etc/apache2/sites-available# ln -s 
../sites-available/forums.feneon.com ./002-forums.feneon.com
(and so on).

I can imagine this sounds cumbersome at first, but once you start 
getting dozens+ VHC, having them each as a file with the 
'sites-available'/'sites-enabled' structure is *really* handy!

Anyway, I hope this helps. Feel free to ask if anything needs clearing up!

Madi
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list