Haproxy 不使用自定义日志格式记录捕获的请求标头

Gag*_*gan 5 haproxy

早些时候我没有指定自定义日志格式,并且捕获的请求标头打印得很好。我想记录unique-id-header,但找不到任何方法。所以我复制粘贴了http://haproxy.1wt.eu/download/1.5/doc/configuration.txt 上提到的日志格式,并且唯一的 id 开始被记录。

不幸的是,现在没有记录捕获的请求标头。该%hrl and %hsl是走出来为空字符串。

很奇怪。这是我的配置,请帮忙:(

listen server
  bind *:80
  mode http

  option  httplog
  option  http-server-close
  no option logasap   # disable early logging of HTTP requests so that total transfer time is logged
  option  forwardfor
  capture request  header    X-Forwarded-For      len 500 
  capture request  header    Host                 len 500 
  capture request  header    X-Request-UID        len 500 
  rspadd  X-Haproxy-Backend:\ server

  # Generate the X-Haproxy-Unique-ID and log it to make it easy to track requests
  log-format %Ci:%Cp\ [id=%ID]\ [%t]\ %f\ %b/%s\ %Tq/%Tw/%Tc/%Tr/%Tt\ %st\ %B\ %cc\ %cs\ %tsc\ %ac/%fc/%bc/%sc/%rc\ %sq/%bq\ {%hrl}\ {%hsl}\ %{+Q}r
  unique-id-format %{+X}o\ %Ci:%Cp_%Fi:%Fp_%Ts_%rt:%pid
  unique-id-header X-Haproxy-Unique-ID
Run Code Online (Sandbox Code Playgroud)

这是我看到的日志:

Sep 13 17:28:57 localhost haproxy[11979]: 10.161.27.218:41592 
[id=0AA11BDA:A278_0AA15B71:0050_505217C5_0014:2ECB] [13/Sep/2012:17:28:37.567]
 server www-example-com-healthz/- 19998/0/2/1/+20001 200 +326
 - - ---- 10/10/1/1/0 0/0 {} {} 
"GET /testing/healthz?merchant=www.example.com&source=elb HTTP/1.1"
Run Code Online (Sandbox Code Playgroud)

请注意,这%hrl and %hsl是空字符串 :( 我如何捕获请求标头??

小智 8

默认情况下,此字段将在日志中显示为空。为了记录标头和 cookie,必须在前端设置捕获参数。

以下是我们如何在 HTTP 请求中捕获客户端发送的标头。

capture request header Referrer len 64
capture request header Content-Length len 10
capture request header User-Agent len 64
Run Code Online (Sandbox Code Playgroud)

  • 已投票但我认为您需要说“Referer”而不是“Referrer”。见 https://en.wikipedia.org/wiki/HTTP_referer#Etymology (4认同)