haproxy为什么只在第一次发送X-Forwarded-For头文件?
这是我已经设置了option forwardfor的(唯一的)地方:
backend nodes mode http balance roundrobin option forwardfor server host ip:80 check
只有第一个HTTP请求包含X-Forwarded-For头部:
Host: example.com User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:44.0) Gecko/20100101 Firefox/44.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Authorization: Basic Og== Connection: keep-alive Cache-Control: max-age=0 X-Forwarded-For: replaced_actual_ip
连续的请求中缺less相同的头文件:
Host: example.com User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:44.0) Gecko/20100101 Firefox/44.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Authorization: Basic Og== Connection: keep-alive Cache-Control: max-age=0
有没有人有一个想法,为什么会发生这种情况?
(我用这个:
tcpdump 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' -n -A
在后端http服务器端转储标题)
首先,为了以这种方式使用Keep Alive,您需要使用HAProxy 1.5。 在1.4中,这是预期的行为。 如果它不适合你,你将需要closures连接。
在1.5中,Keep Alive的默认代理模式将具有预期的行为。 如果您查看HAProxy 1.5手册,在第1.1节“交易模型”中,您将看到5种连接模式。 其中之一就是“隧道”,这是HAProxy在保持活力连接版本1.5之前的行为,并将帮助您理解为什么它的行为如此。