【发布时间】:2020-11-25 12:59:51
【问题描述】:
我正在尝试使用 X_FORWARDED_FOR 将到达 haproxy 的 source/client_ip(%ci) 转发到应用程序。
HA-Proxy 版本 1.7.9 2017/08/18
global
log 127.0.0.1 local1 info
daemon
user vcap
group vcap
maxconn 64000
spread-checks 4
defaults
maxconn 64000
option http-server-close
option httplog
option forwardfor
frontend http-in
mode http
bind :80
log global
option forwardfor except 127.0.0.1
frontend https-in
mode http
log global
bind :443 ssl crt /data/haproxy/ssl/server.pem
option forwardfor except 127.0.0.1
use_backend https-backend
http-request set-header SSL_CLIENT_CERT_USER %{+Q}[ssl_c_s_dn(cn)]
http-request set-header SSL_CLIENT_CERT %{+Q}[ssl_c_der,base64]
http-request set-header SSL_CLIENT_CERT_USED %[ssl_c_used] if no_user_cert
backend https-backend
mode http
log global
balance roundrobin
option forwardfor header X-Client
Java 应用程序执行以下操作:
String ipAddress = request.getHeader("HTTP_X_FORWARDED_FOR");
if (ipAddress == null) {
ipAddress = request.getRemoteAddr();
}
完成上述配置后,我在应用程序日志中获得了 haproxy 的 IP,而不是实际的源 IP。
在前端或后端或两侧添加 set-header 没有帮助:
http-request set-header X-CLIENT-IP %[src].
我做错了吗?
【问题讨论】:
标签: java reverse-proxy haproxy