FreeBSD Mailman with nginx

I recently had to setup a Mailman install for a few local groups to use for a discussion list. Mailman recommends using Apache for web interface but I was running this on a small-ish VPS so I wanted to use nginx for its thinner profile.

Install the required software via ports:

cd /usr/ports/mail/postfix
make install

cd /usr/ports/mail/mailman
make install

Make sure you select postfix for the MTA.

cd /usr/ports/www/nginx
make install

I added the options for rewrite and SSL support.

cd /usr/ports/www/fcgiwrap
make install

Set the services to run at boot:

echo "postfix_enable="YES"" >> /etc/rc.conf
echo "nginx_enable="YES"" >> /etc/rc.conf
echo "fcgiwrap_enable="YES"" >> /etc/rc.conf
echo "fcgiwrap_user="www"" >> /etc/rc.conf
echo "mailman_enable="YES"" >> /etc/rc.conf

Configuration: By default FreeBSD installs the mailman port to /usr/local/mailman. You'll need to edit toe /usr/local/mailman/Mailman/mm_cfg.py file to reflect the hostname you'll be using.

DEFAULT_URL_PATTERN = 'http://%s/'
DEFAULT_EMAIL_HOST = 'lists.example.com'
DEFAULT_URL_HOST = 'lists.example.com'

fcgiwrap does not require and addtional configuration to get working. Postfix needs to be told what domains it's handling mail for:

cd /usr/local/etc/postfix

add the following lines to main.cf:

myhostname = fqdn.example.com

If you're going to be running mailman on a vhost add it here:

mydestination = $myhostname, localhost.$mydomain, localhost, otherfqdn.example.com

This step is not needed if you're hostname matches the host Mailman will be using.

Restart postfix:
/usr/local/etc/rc.d/postfix restart

nginx:

I decided to host Mailman on a vhost so I added a few things to the default nginx config:

cd /usr/local/etc/nginx 
mkdir vhost.d

Then add the following line to nginx.conf in the http{} stanza:

include /usr/local/etc/nginx/vhost.d/*.conf;

I also uncommented the gzip on line. No need to waste bandwitdh. Now configure the nginx vhost:

server {
   listen       80;
   server_name lists.example.com www.lists.example.com;
   access_log /var/log/lists.example.com.log;
   root /usr/local/mailman/cgi-bin;

       location = / {
               rewrite ^ /mailman/listinfo permanent;
       }

       location / {
               rewrite ^ /mailman$uri;         
       }

       location ~ ^/mailman(/[^/]*)(/.*)?$ {
               fastcgi_split_path_info (^/mailman/[^/]*)(.*)$;
               include fastcgi_params;
               fastcgi_param GATEWAY_INTERFACE CGI/1.1;
               fastcgi_param SCRIPT_FILENAME $document_root$1;
               fastcgi_param PATH_INFO $fastcgi_path_info;
               fastcgi_param PATH_TRANSLATED $document_root$2;
               fastcgi_pass  unix:/var/run/fcgiwrap/fcgiwrap.sock;
       }

       location /images/mailman {
               alias /usr/local/mailman/icons;
       }

       location /icons {
               alias /usr/local/mailman/icons;
       }

       location /pipermail {
               alias /usr/local/mailman/archives/public;
               autoindex on;
       }
}

Restart nginx:

/usr/local/etc/rc.d/nginx restart

Now you can start creating lists with mailman, first you need create the mailman list

/usr/local/mailman/bin/newlist --urlhost=lists.example.com --emailhost=lists.example.com mailman

Once them mailman list has been created you can start the Mailman service:

/usr/local/etc/rc.d/mailman start

You should now have a fully functional Mailman service.