我正在尝试在haproxy节点上获取请求者的主机/IP。我的haproxy配置如下:
frontend www-http
bind *:9000
http-request redirect location https://%fi:9143
frontend www-https
bind *:9143 ssl crt /root/keys.pem
reqadd X-Forwarded-Proto:\ https
default_backend www-backend
backend www-backend
balance roundrobin
cookie SERVERID insert indirect nocache
server server1 1.1.1.1:9080 cookie server1 weight 1 maxconn 1024 check
在这里,如果有任何http请求,则需要转发到https。现在请求可能是以IP地址或完全限定形式的主机名的形式出现的,如下所示:
http://10.10.10.10:9000
需要将此转发至https://10.10.10.10:9143
同样,请求可能以完全限定的主机名形式出现,例如:
http://myhost.domain.com:9000
需要将此内容转发到https://myhost.domain.com:9143
基本上10.10.10.10和myhost.domain.com是同一个系统。
现在,使用上述haproxy配置,由于它是%fi(frontend_ip),因此我无法获得以下信息,因此它会重定向到https://10.10.10.10:9143
因此,我的问题是如何在haproxy节点到达haproxy时获取其ip/host。
我尝试了以下选项,但没有成功:
http-request redirect location https://%f:9143
http-request redirect location https://%[req.hdr(Host)]:9143
翻译来源:https://www.haproxy.com/doc/aloha/7.0/haproxy/log_format_rules.html
这是有关HAProxy日志格式规则的文档。