How to divert traffic based on hostname using HAProxy?

Solution 1:

Here is an example:

frontend http
        bind 0.0.0.0:80
        default_backend www
        # NAT static host names and static paths in other hostnames to a different backend
        acl host_static hdr_beg(host) -i static.
        acl url_static  path_beg         /static
        use_backend static if host_static or url_static

backend www
        balance roundrobin
        server  qa1 10.177.1.81:80
        server  qa2 10.177.1.45:80

backend static
        balance roundrobin
        server  media1 10.177.0.86:80