1
votes

I am having this problem to find unique visitors to my site. The site is deployed on AWS cloud. The first hit goes to load balancer which routes to varnish cache (type of reverse proxy) and which inturn routes to apache web server. I have the below config inside my apache conf file:

LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{forensic-id}n\"" varnishcombined

CustomLog logs/access_log varnishcombined

inside my varnish file I have following: sub vcl_recv {

unset req.http.X-Forwarded-For;
set req.http.X-Forwarded-For = client.ip;

When I check my access log, I see that all requests have the load balancer IP rather than the actual IP of the client from where request has come. nfact it is the ip of the aws load balancer.

If i remove any one that is either varnish or load balancer my access log has correct entries capturing the client IP addresses.

Has anybody faced this situation?

Manguesh

2

2 Answers

2
votes

Use this in sub vcl_recv have a list of IP's (including your ELB and Client IP)

if (req.restarts == 0) {
    if (req.http.X-Forwarded-For) {
        set req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " + client.ip;
    } else {
        set req.http.X-Forwarded-For = client.ip;
    }
}
0
votes

Ok guys, So the fix is simple. All I had to do was remove following lines from my varnish config file :

unset req.http.X-Forwarded-For; set req.http.X-Forwarded-For = client.ip;

Initially I only had varnish and apache as backend, thefore the above lines were necessary to propagate the client ip. However, with the addition of load balancer above varnish proxy, the same lines trimmed the http header for client ip propagation and instead set the load balancer Ip as client.

Manguesh