Skip to content

Instantly share code, notes, and snippets.

@cosimo
Created January 13, 2012 18:03
Show Gist options
  • Save cosimo/1607818 to your computer and use it in GitHub Desktop.
Save cosimo/1607818 to your computer and use it in GitHub Desktop.
Varnish X-Forwarded-For VCL snippet
# See http://www.varnish-cache.org/trac/ticket/540
sub inject_forwarded_for {
# Rename the incoming XFF header to work around a Varnish bug.
if (req.http.X-Forwarded-For) {
# Append the client IP
set req.http.X-Real-Forwarded-For = req.http.X-Forwarded-For ", " regsub(client.ip, ":.*", "");
#unset req.http.X-Forwarded-For;
}
else {
# Simply use the client IP
set req.http.X-Real-Forwarded-For = regsub(client.ip, ":.*", "");
}
}
# ... and then later in vcl_recv()
#call inject_forwarded_for;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment