Jump to content

HAProxy

From Official NixOS Wiki

HAProxy is an open-source software tool used for load balancing and proxying TCP and HTTP applications. It helps manage incoming traffic by distributing it across multiple servers, enhancing both reliability and scalability. Key features include health checks, session persistence, and SSL termination, making it a practical choice for handling web service traffic effectively.

Setup

The following example configures HAProxy to forward all incoming SMTP mail traffic to an internal mail server on 10.250.0.8 and fdc9:281f:4d7:9ee9::8.

❄︎ /etc/nixos/configuration.nix
services.haproxy = {
  enable = true;
  config = ''
    global
      log /dev/log local0
      daemon
      maxconn 2048
    defaults
      log     global
      mode    tcp
      option  tcplog
      timeout connect 10s
      timeout client  1m
      timeout server  1m
    frontend smtp_in
      bind *:25 v4v6
    default_backend smtp_backend
      backend smtp_backend
      server homeserver 10.250.0.8:25 check send-proxy
      server homeserver_v6 [fdc9:281f:4d7:9ee9::8]:25 check send-proxy
    '';
  };
};

The send-proxy option enables Proxy Protocol which is useful in combination with mail servers such Stalwart.