3

I'm migrating some infrastructure from multiple servers hosting specific sites to a load-balancing architecture using HAProxy 1.3.15.7 on OpenBSD 4.6 macppc. Naturally, I'm starting with configuring content switching for the current setup (specific sites on specific servers) and my /etc/haproxy/haproxy.cfg is as follows:

global
    log 127.0.0.1   local0
    log 127.0.0.1   local1 notice
    #log loghost    local0 info
    maxconn 1024
    chroot /var/haproxy
    uid 604
    gid 604
    daemon
    #debug
    #quiet
    pidfile /var/run/haproxy.pid

defaults
    log     global
    mode    http
    option  httplog
    option  dontlognull
    option  redispatch
    retries 3
    maxconn 2000
    contimeout      5000
    clitimeout      50000
    srvtimeout      50000
    stats enable
    stats auth user:pass

frontend http_proxy *:80
    # check to see which domain the reguest is for
    acl host_tld.domain.sub1 hdr_end(host) sub1.domain.tld
    acl host_tld.domain.sub2 hdr_end(host) sub2.domain.tld
    # send to the correct server
    use_backend server2 if host_tld.domain.sub1 or host_tld.domain.sub2
    default_backend server1

backend server1
    server httpd_server1 192.168.1.3:80

backend server2
    server httpd_server2 192.168.1.4:80

The goal is for all domains to be served by server1 except for domains sub1.domain.tld & sub2.domain.tld which should be dished out by server2 instead. However, when I try to start HAProxy, I get the following errors:

parsing /etc/haproxy/haproxy.cfg : backend 'server2' has no dispatch address and is not in transparent or balance mode.
parsing /etc/haproxy/haproxy.cfg : backend 'server1' has no dispatch address and is not in transparent or balance mode.
Errors found in configuration file, aborting.
Error reading configuration file : /etc/haproxy/haproxy.cfg

I've looked at the examples listed in the HAProxy 1.3 documentation and http://upstre.am/2008/01/09/using-haproxy-with-multiple-backends-aka-content-switching/, but don't see where I've gone wrong. None of the examples seem to require either option transparent nor a balance mode. Also, the documentation for the dispatch option is curiously omitted from the 1.3 documentation, but I doubt it would be helpful in my troubleshooting anyway.

Where have I gone wrong?

1 Answer 1

2

You forgot the line "balance roundrobin" (or equivalent) as you need to have a balancing algorithm in a backend. Also, you're doing content switching, so please add "option httpclose" in your frontend or defaults section, otherwise second requests of keep-alive connections will not be matched.

3
  • Thanks, I had just found out on the HAProxy mailing list that balance roundrobin wasn't a built-in default until version 1.3.16 (and I'm running 1.3.15.7) and that definitely resolved the issue. Extra thanks for the reminder about option httpclose.
    – morgant
    Jan 20, 2010 at 22:03
  • @Willy Tarreu - Is that advice still valid for 1.6? (ie. do we need to do httpclose when content switching?)
    – UpTheCreek
    Oct 22, 2015 at 11:13
  • @UpTheCreek: no, you're right, we don't need this anymore in 1.5 nor 1.6. "balance roundrobin" is the default, and since http-keep-alive is supported it is the default as well. Nov 20, 2015 at 7:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .