Jon*_*sen 2 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
Run Code Online (Sandbox Code Playgroud)
我调用代理:
curl 127.0.0.1
Run Code Online (Sandbox Code Playgroud)
然后我期待在日志中看到自定义标题,但它没有显示:
Nov 10 17:49:36 localhost haproxy[22355]: Foo - {} -
Run Code Online (Sandbox Code Playgroud)
出现硬编码的“Foo”,因此该log-format命令显然有效。但是其他所有内容都呈现为空...是否在登录后设置了自定义标头?如何记录自定义标题?
我是 HAProxy 的新手,所以我认为这可能是我缺少的一些理解。
(我用 cmd 启动 HAProxysudo haproxy -f /etc/haproxy/haproxy.cfg并用 观察日志sudo tail -f /var/log/haproxy/haproxy.log。这是在 HA-Proxy 版本 1.6.2 上)
你可以使用这个:
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
Run Code Online (Sandbox Code Playgroud)
请注意captureget 之前执行http-request,因此您无法记录 Foo。
| 归档时间: |
|
| 查看次数: |
6846 次 |
| 最近记录: |