If I use the following configuration in varnish,
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;
}
}
and configure apache logformat like this,
LogFormat "%{X-Forwarded-For}i %t \"%r\" %>s %b \"%{User-agent}i\"" varnishcombined
CustomLog ${APACHE_LOG_DIR}/access.log varnishcombined
I end up with the forwarded ip (client's ip) being displays twice in apache's logs. But if I simply use:
unset req.http.x-forwarded-for;
set req.http.x-forwarded-for = client.ip;
Then it works just fine. But the question is, why is the ip being shown twice in the first example?
I'm using Ubuntu 16.04.5, apache 2.4.18 and varnish 4.1.10-1~xenial.