Qmailadmin with Apache

Configuring Qmailadmin to work with the Apache webserver

Create the directories to hold the webmail and Qmailadmin related web files:

mkdir -p /var/websites/mail/htdocs
mkdir -p /var/websites/mail/cgi-bin
mkdir -p /var/websites/mail/logs

Assuming you are using Apache, installed as per this site's install guide:

  • Without ezmlm:
    cd /extra/src/qmailadmin-1.2.12
    ./configure \
    --enable-cgibindir=/var/websites/mail/cgi-bin \
    --enable-htmldir=/var/websites/mail/htdocs \
    --enable-ezmlmdir=n
  • With ezmlm:
    cd /extra/src/qmailadmin-1.2.12
    ./configure \
    --enable-cgibindir=/var/websites/mail/cgi-bin \
    --enable-htmldir=/var/websites/mail/htdocs \
    --enable-ezmlmdir=/usr/local/bin/ezmlm \
    --disable-ezmlm-mysql

Then compile qmailadmin, and install it:

make && make install-strip

Apache virtual host configuration
Edit /usr/local/apache2/conf/extra/httpd-vhosts.conf and add a virtualhost directive for Qmailadmin and webmail:
<VirtualHost *:80>
    ServerAdmin postmaster@example.com
    DocumentRoot /var/websites/mail/htdocs
    ServerName mail.example.com

  <Directory /var/websites/mail/htdocs>
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>

  ScriptAlias /cgi-bin/ "/var/websites/mail/cgi-bin/
  <Directory "/var/websites/mail/cgi-bin">
    AllowOverride None
    Options FollowSymLinks
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

Securing Qmailadmin
If you are going to have Qmailadmin accessible from the public internet, you should encrypt the connection as user IDs and passwords are used.

Assuming you've already created an SSL certificate according to the Apache SSL Instructions:

Because qmailadmin is a program within /var/websites/webmail/cgi-bin, we'll have to adjust the settings for that directory. Add a RewriteRule to force clients to connect to the qmailadmin interface through an SSL encrypted session. If you don't want your internal users to be encrypted, adjust the REMOTE_ADDR RewriteCond to reflect your internal network. If you want all IPs encrypted, remove that condition altogether. Note that the Options directive is changed from "None" to "FollowSymLinks". The example below will redirect requests from any addresses other than the 192.168.0/24 range to HTTPS on port 443.
Edit /usr/local/apache2/conf/extra/httpd-vhosts.conf and modify the Directory section for /var/websites/webmail/cgi-bin, adding the Rewrite rule and conditions:

<Directory "/var/websites/mail/cgi-bin">
  AllowOverride None
  Options FollowSymLinks
  Order allow,deny
  Allow from all
  RewriteEngine on
  RewriteCond %{REMOTE_ADDR} !^192\.168\.0\.[0-9]+$
  RewriteCond %{HTTPS} !=on
  RewriteRule ^.*qmailadmin https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
</Directory>