【发布时间】:2017-09-25 20:22:48
【问题描述】:
我正在尝试获取 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 节点的 ip/host,因为它涉及到 haproxy。
我尝试了以下选项,但没有成功:
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
【问题讨论】: