记录HAProxy自定义标头

时间:2017-11-10 17:54:11

标签: logging redhat haproxy

我希望让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上)

1 个答案:

答案 0 :(得分:3)

您可以使用:

http-request add-header Foo Bar
#capture request header Foo len 64
http-request capture req.hdr(Foo) len 64
log-format Foo\ %[capture.req.hdr(0)]\ %hr\ %hrl\ %hs\ %hsl  

请注意capturehttp-request之前执行,因此您无法记录Foo。

相关问题