Skip to content

Instantly share code, notes, and snippets.

@cosimo
Created February 26, 2018 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cosimo/a88fd27eb62b86c607f0f0cb7c66aed9 to your computer and use it in GitHub Desktop.
Save cosimo/a88fd27eb62b86c607f0f0cb7c66aed9 to your computer and use it in GitHub Desktop.
Varnish: clean up 127.0.0.1 from X-Forwarded-For header in VCL
#
# Varnish appends ${localhost} (= 127.0.0.1) to the XFF header
# automatically and transparently *before* calling vcl_recv().
#
# Not a problem for the Rest backend, but in the interest of
# trying to be as transparent as possible, we have the option
# to clean it out.
#
sub clean_x_forwarded_for {
if (req.http.X-Forwarded-For != "") {
set req.http.X-Forwarded-For = regsub(req.http.X-Forwarded-For,
"^(.+)\s*,\s*127\.0\.0\.1$", "\1");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment