I've had some initial success with HAProxy setting up a bunch of app servers listening on various other ports.

I now have another webserver listening on one port, and i'd like to what changes to make to my config to flow traffic by hostname as well.

The following is the current setup, assuming:

  • my apache webserver is running at examplecom:8001
  • my bunch of app servers, ,
  log local0
  log local1 notice
  maxconn 4096
  #user haproxy
  #group haproxy

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

listen appservers
  mode http
  balance roundrobin
  option httpclose
  option forwardfor
  #option httpchk HEAD /check.txt HTTP/1.0
  server  inst1 cookie server01 check inter 2000 fall  3
  server  inst2 cookie server02 check inter 2000 fall  3
  server  inst3 cookie server01 check inter 2000 fall  3
  server  inst4 cookie server02 check inter 2000 fall  3
  capture cookie vgnvisitor= len 32

(any other comments on the ^ setup are welcome.)

Now I'd like to continue the same above, but in addition in case - if the hostname is myspecialtopleveldomain<dot>com, then would like to flow traffic to example<dot>com:8001


  • 2
    It is possible to send requests to different servers based on the hostname using frontend & backend configuration. Your question is a little confusing though, you mention example.com:8001, but it's not in the config anywhere. Is that the destination for requests to myspecialtopleveldomain.com on port 80? Perhaps you can give a few sample URLs that users would enter and where you want those URLs to be sent by haproxy. – ThatGraemeGuy Feb 12 '10 at 9:30

Here is an example:

frontend http
        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
        server  qa2

backend static
        balance roundrobin
        server  media1
  • Thanks for the sample config, you've just helped me finalise our load-balancer config :) – isNaN1247 Mar 18 '11 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.