HAProxy config file error using req.cook

access-control-listconfigurationhaproxy

I'm following this tutorial (more or less) in an attempt to use haproxy for a quick-and-easy A/B testing setup, and haproxy doesn't like my config file for some reason that I just can't identify.

Config file:

global  
log    127.0.0.1 local1 debug
chroot /var/lib/haproxy
user   haproxy
group  haproxy
daemon

defaults  
log     global
mode    http
option  httplog
option  dontlognull
    timeout connect 5000
    timeout client  50000
    timeout server  50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http

frontend http
bind *:80

acl is_current-area_cookie req.cook(Current-Area) -m found
acl is_new-area_cookie     req.cook(New-Area) -m found
## Other ACL's

use_backend current_area   if is_current-area_cookie
use_backend new_area       if is_new-area_cookie

use_backend weighted_area  if !is_current-area_cookie !is_new-area_cookie
## Other Backend handling

backend current_area
    server current_area 127.0.0.1:81

backend new_area
    server new_area     127.0.0.1:82

backend weighted_area
    server current_area 127.0.0.1:81 weight 70
    server new_area     127.0.0.1:82 weight 30

And the errors:

[ALERT] 063/165427 (31203) : parsing [/etc/haproxy/haproxy.cfg:27] : error detected while parsing ACL 'is_current-area_cookie'.
[ALERT] 063/165427 (31203) : parsing [/etc/haproxy/haproxy.cfg:28] : error detected while parsing ACL 'is_new-area_cookie'.
[ALERT] 063/165427 (31203) : parsing [/etc/haproxy/haproxy.cfg:31] : error detected while parsing switching rule.
[ALERT] 063/165427 (31203) : parsing [/etc/haproxy/haproxy.cfg:32] : error detected while parsing switching rule.
[ALERT] 063/165427 (31203) : parsing [/etc/haproxy/haproxy.cfg:34] : error detected while parsing switching rule.
[ALERT] 063/165427 (31203) : Error(s) found in configuration file : /etc/haproxy/haproxy.cfg
[ALERT] 063/165427 (31203) : Fatal errors found in configuration.

I've been through all of HAProxy's documentation, especially the stuff about req.cook() and can't find anything wrong with my syntax…

Best Answer

Turns out Ubuntu's repos contain a rather old (1.4) version of HAProxy and this example uses some directives that were added in 1.5.

After upgrading to the latest stable release (1.6) this config works.

Related Topic