
我有一个以编程方式构建的 HAProxy 配置文件,并且对于定义的每个后端,我都会收到如下错误:
[WARNING] 073/153725 (1663) : parsing [/etc/haproxy/haproxy.cfg:964] : 'use_backend' ignored because backend 'bk_10716' has no frontend capability.
我的配置文件相当简单,只有一个后端的简化版本似乎可以工作,所以我无法指出哪里出了问题。
我的配置文件包括以下内容:
global
tune.ssl.default-dh-param 2048
log 127.0.0.1 local1 debug
chroot /var/lib/haproxy
user haproxy
group haproxy
maxconn 4000
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
listen stats
bind *:1234
stats auth admin:bdi2016
stats uri /
stats realm Haproxy\ Statistics
stats enable
mode http
frontend http:
bind *:80
mode http
option httpclose
option forwardfor
接下来是大量这样的:
use_backend bk_10011 if { hdr_end(host) -i somedomainname.com }
backend bk_10011
server server_10011 127.0.0.1:10011 check
我是否只是忽略了一些显而易见/愚蠢的事情?
答案1
它曾是use_backend if
只是一个愚蠢的错误。我需要在前端中指定所有语句,而不是在每个单独的后端上方指定。这就是为什么它只适用于一个后端,因为无论缩进如何,第一个use_backend
“属于”后端frontend http:
,并且每个后续后端都显得孤立。
答案2
您需要为前端分配一个 ID 号(例如,ID 1)。然后您需要将该 ID 分配给后端配置以进行匹配。
因此在前端它将是这样的:
frontend http:
id 1
bind *:80
mode http
option httpclose
option forwardfor
在后端像这样:
use_backend bk_10011 if { hdr_end(host) -i somedomainname.com }
backend bk_10011
server server_10011 127.0.0.1:10011 id 1 check
至少这对我有用。