Created
February 9, 2017 21:49
-
-
Save alvarow/fa409edc70aeb4cf89bbc83c1c78f392 to your computer and use it in GitHub Desktop.
Sets Squid Proxy to log IP address from X-Forwarded-For header instead of the real client ip address if the X-Forwarded-For header exists.
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
# Has XFF header with a value | |
acl has-xff req_header X-Forwarded-For ^(([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)|(\[([0-9a-f]+)?:([0-9a-f:]+)?:([0-9a-f]+|0-9\.]+)?\])) | |
# default logformat | |
logformat squid %ts.%03tu %6tr %>a %Ss/%03>Hs %<st %rm %ru %[un %Sh/%<a %mt | |
# default logformat using XFF instead of client IP address | |
logformat squid-xff %ts.%03tu %6tr %{X-Forwarded-For}>h %Ss/%03>Hs %<st %rm %ru %[un %Sh/%<a %mt | |
# If no XFF header, use default format | |
access_log stdio:/var/log/squid/access.log squid !has-xff | |
# If XFF use XFF format | |
access_log stdio:/var/log/squid/access.log squid-xff has-xff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is smarter, but requires Squid v3.5+: