Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 0.0.0.0:8081, 0.0.0.0:8082 , 0.0.0.0:8083
global
  log 127.0.0.1 local0
  log 127.0.0.1 local1 notice
  maxconn 4096
  debug
  #quiet
  #user haproxy
  #group haproxy

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

listen appservers 0.0.0.0:80
  mode http
  balance roundrobin
  option httpclose
  option forwardfor
  #option httpchk HEAD /check.txt HTTP/1.0
  server  inst1 0.0.0.0:8081 cookie server01 check inter 2000 fall  3
  server  inst2 0.0.0.0:8082 cookie server02 check inter 2000 fall  3
  server  inst3 0.0.0.0:8083 cookie server01 check inter 2000 fall  3
  server  inst4 0.0.0.0:8084 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

~B

share|improve this question
1  
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
add comment

2 Answers

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
share|improve this answer
    
Thanks for the sample config, you've just helped me finalise our load-balancer config :) –  codetwizzle Mar 18 '11 at 13:50
add comment

You can use ACL's in HAProxy to load balance based on host headers:

Using the ACL in HAProxy for Load Balancing Named Virtual Hosts

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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