Synopsis

You want to use Aloha load balancer in front of a mail platform, relying on HAProxy to achieve load-balancing.
You mail platform delivers IMAP acts as a SMTP relay for your users.
You want your users to use the same server for both protocols in order to take advantage of different caches level (FS cache, authentication, etc…)

Configuration

The HAProxy configuration below explain how to force the SMTP relay for IMAP connected users.
Users relaying mail through SMTP will be connected to any server in the farm using round robin.

[sourcecode language=”text”]
frontend ft_smtp
bind :25
mode tcp
default_backend bk_smtp

frontend ft_imap
bind :143
mode tcp
default_backend bk_imap

backend bk_smtp
mode tcp
balance roundrobin
stick match src table bk_imap
server s1 192.168.1.1:25 check
server s2 192.168.1.2:25 check

backend bk_imap
mode tcp
# imap connections are usually long
balance leastconn
stick store-request src
stick-table type ip size 200k expire 30m
server s1 192.168.1.1:143 check
server s2 192.168.1.2:143 check
[/sourcecode]

Links