Scenario

With the popularity of DSL connection, an office or individual behind the Internet may have the similar setup.

  • Single public IP address (whatismyip.com to lookup)
  • Virtualization Managment with KVM and containers e.g. Proxmox, VirtualBox, VMware, etc
  • Registered Domain name e.g. mydomain.com
  • Range of web applications:
    • Project Management – Redmine (VM1)
    • EMail – Zimbra  (VM2)
    • CMS – Drupal (VM3)
    • ERP – ADempiere (VM4)

Objective

To provide external access to individual web applications using subdomain i.e. redmine.mydomain.com –> VM1

Solution

1. Install haproxy onto Proxmox host

apt-get install haproxy

2. Edit /etc/default/haproxy to enable init script to start haproxy

# Set ENABLED to 1 if you want the init script to start haproxy.
ENABLED=1
# Add extra flags here.
#EXTRAOPTS="-de -m 16"

3. Edit /etc/haproxy/haproxy.cfg to run on port 8080 (if default port 80 is already taken) and setting server redirction

# this config needs haproxy-1.1.28 or haproxy-1.2.1

global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
maxconn 4096
nbproc 4
user haproxy
group haproxy
daemon

defaults
log global
mode http
option httplog
option dontlognull
retries 3
contimeout 5000
clitimeout 50000
srvtimeout 50000
maxconn 2000
balance roundrobin
stats enable
stats uri /haproxy?stats

frontend haproxy

bind 0.0.0.0:80

acl is_redmine hdr_end(host) -i redmine.mydomain.com
acl is_adempiere hdr_end(host) -i adempiere.mydomain.com

use_backend redmine_servers if is_redmine

use_backend adempiere_servers if is_adempiere

backend redmine_servers

server redmine 192.168.0.10:80 weight 1 maxconn 512 check

backend adempiere_servers
server adempiere 192.168.0.20:80 weight 1 maxconn 512 check

High Availability Load Balancing using HAProxy
Tagged on: