Many times there is a need to publish multiple websites from internal network, but there is only one public IP address available.

How this can be done easy way? HAProxy can help us with it.

In example configuration I have 2 URLs registered to same public IP address:


Here is how HAProxy configuration for given example looks like…


        log   local0
        log   local1 notice
        #log loghost    local0 info
        maxconn 4096
        chroot /var/lib/haproxy
        user haproxy
        group haproxy

        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        maxconn 2000
        contimeout      5000
        clitimeout      50000
        srvtimeout      50000

frontend MAIN
    bind *:80
    mode http
    acl FIRST_URL hdr_dom(host) -i
    acl SECOND_URL hdr_dom(host) -i
    acl THIRD_URL hdr_dom(host) -i
    use_backend FIRST if FIRST_URL
    use_backend SECOND if SECOND_URL
    use_backend THIRD if THIRD_URL

backend FIRST
    mode http
    server web-first
backend SECOND
    mode http
    server web-second
backend THIRD
    mode http
    server web-third

All requests to external URLs will be redirected to appropriate internal servers.

Enabling HAProxy Statistics

For monitoring/tracking purposes it might be also useful to enable statistics in HAProxy configuration.

listen stats AAA.BBB.CCC.DDD:8989
        mode http
        stats enable
        stats uri /stats
        stats realm HAProxy\ Statistics
        stats auth admin:admin

Above part has to be added to /etc/haproxy/haproxy.cfg configuration file.

Once it will be added refer to:


enter username admin and password admin to display HAProxy statistics.

Of course AAA.BBB.CCC.DDD has to be replaced with appropriate IP address of HAProxy server on which statistics web page should be available.