We have our setup as follows: 1. Varnish (Receives traffic and serves from cache whenever possible) 2. Haproxy (on same machine with Varnish, load balance requests to web servers) 3. Apache (in separate servers, traffic balanced by Haproxy).
Now I want to log real user IP in web server access log, for which I have enabled logging of "X-farwarded-for" header which is logging "127.0.0.1".
Enabled this header in Varnish (relevant lines from default.vcl):
sub vcl_pipe {
set req.http.connection = "close";
return (pipe);
}
sub vcl_fetch {
set req.http.X-Forwarded-For = req.http.rlnclientipaddr;
return(deliver);
}
Also enabled in HAProxy (relevant lines from config file):
option http-server-close
option forwardfor except 127.0.0.1
Needs suggestions where things needs to be fixed for getting real user IP in backend server.