I deploy a java web application in a cf v2 environment. The application needs get the real request ip of the client from the any valid http request to the request page.
The configuration of the haproxy in this cf is as following, and the groute is also set the option for X-Forwarded-For:
global
log 127.0.0.1 syslog info
daemon
maxconn 64000
spread-checks 4
defaults
log global
timeout connect 30000ms
timeout client 300000ms
timeout server 300000ms
option httpclose
option forwardfor
frontend http_in
mode http
bind :80
option httplog
option httpclose
option forwardfor
reqadd X-Forwarded-Proto:\ http
default_backend http-nginxs
backend http-nginxs
mode http
balance roundrobin
backend tcp-nginxs
mode tcp
balance roundrobin
Theoretically, the servlet can get acquire the client ip from the X-Forwarded-For header. But the printing log of the servlet shows it can't always acquire the client ip from the X-Forwarded-For header.
Most of the time, there is only ip of haproxy in X-Forwarded-For header, and sometimes ips of client and haproxy both exist.
After capturing the package via tcpdump, i guess that the problem just exists in the haproxy. haproxy only adds the X-Forwarded-For header for a request matching one of the following conditions:
1.The url of the request hasn't been dispatch to any gorouter, or has been into the gorouter selected by current balance algorithm.
2.The session of the request is new. That is to say current cookies of this request is newly generated and has not been processed by the HA.
These conditions are figured out by assumption based on tcp package capturing. The HA may have some cache mechanism to achieve such effects.
Does anyone know how to configure the HA to make it add X-Forwarded-For header for every valid http request without such cache mechanism?
Or how can the java application running in CF can get real client ip with or even without X-Forwarded-For header for every http request?
With great appreciation to anyone, who can give me some advice or solution.