Created
January 13, 2012 18:03
-
-
Save cosimo/1607818 to your computer and use it in GitHub Desktop.
Varnish X-Forwarded-For VCL snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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