Lei Wu, Web Developer

Keeping simple things simple.

Use X-Forwarded-For in Varnish Apache/NCSA Logs

In Varnish 4.0, the command varnishncsa let you display logs in Apache style format.

By default, the log format is %h %l %u %t "%r" %s %b "%{Referer}i" "%{User-agent}i".

But if you need to use “X-Forwarded-For” IP instead of %h (Remote host), this is how:

1
varnishncsa -F '%{X-Forwarded-For}i %l %u %t "%r" %s %b "%{Referer}i" "%{User-agent}i"'