【发布时间】:2017-11-11 10:46:31
【问题描述】:
我希望 HAProxy 设置自定义标头并记录它。
下面是我的 haproxy.cfg 的一个配对示例(我遗漏了一些 SSL 细节和多个我认为与我的问题无关的后端)
global
log 127.0.0.1 local0 debug
defaults
log global
stats enable
option httplog
frontend httpFrontendi
mode http
bind *:80
http-request add-header Foo Bar
capture request header Foo len 64
log-format Foo\ %[capture.req.hdr(0)]\ %hr\ %hrl\ %hs\ %hsl
default_backend backend_api
redirect scheme https code 301 if !{ ssl_fc }
backend backend_api
mode http
balance roundrobin
option httpchk HEAD /api/test_db HTTP/1.0
server backend_api1 ip:80 check inter 5s rise 2 fall 3
我用以下方式调用代理:
curl 127.0.0.1
然后我希望在日志中看到自定义标题,但它没有显示:
Nov 10 17:49:36 localhost haproxy[22355]: Foo - {} -
出现硬编码的“Foo”,因此log-format 命令显然有效。但是其他所有内容都呈现为空......是在记录后设置的自定义标题吗?如何记录自定义标头?
我是 HAProxy 的新手,所以我认为这可能是我缺少的一些理解。
(我使用 cmd sudo haproxy -f /etc/haproxy/haproxy.cfg 启动 HAProxy,并使用 sudo tail -f /var/log/haproxy/haproxy.log 观察日志。这是在 HA-Proxy 版本 1.6.2 上)
【问题讨论】: