我在网上跟随了大量的参考文献,告诉我我应该能够build立一个前端,如:
frontend http_https bind 1.2.3.4:443 ssl crt /etc/haproxy/tls/mycert.pem bind 1.2.3.4:80 mode http option httplog option forwardfor option http-server-close redirect scheme https code 301 if !{ ssl_fc } http-request set-header X-Forwarded-Port %[dst_port] http-request add-header X-Forwarded-Proto https if { ssl_fc } http-request set-header X-Request-Start t=%Ts%ms http-response set-header Strict-Transport-Security max-age=15768000 use_backend %[req.hdr(host),lower,map(/etc/haproxy/domains-to-backends.map)]
当我在后端服务器上使用tcpdump时,我看到所有的add-header和set-header文件,但是我看不到任何X-Forwarded-For头文件。
如果我添加如下内容:
http-request add-header X-Client-IP %[src]
我确实看到传递的头文件和正确的客户端IP。
任何人都可以提供任何洞察,为什么这可能不工作? 或者任何原因,我不应该只使用http-request set-header X-Forwarded-For %[src]而不是option forwardfor ?
示例后端部分:
backend bk_foo balance roundrobin errorfile 502 /etc/haproxy/errorfiles/502.http errorfile 503 /etc/haproxy/errorfiles/503.http errorfile 504 /etc/haproxy/errorfiles/504.http option httpchk server foo.example.com 10.1.2.3:8080 check
编辑:你应该把option forwardfor在后端部分。 不在前端部分。
我不认为HAProxyconfiguration有什么问题。 我已经做了许多configurationforwardfor选项没有任何问题。 HAProxy和后端服务器之间有可能会移除某些标头的设备吗? 此外,我会build议testing一个简单的设置侧重于这个头,以确保其他configuration不会导致问题。