Squid: disable X-Forwarded-For, but only for specific ACLs

squidx-forwarded-for

I know, that I can turn off X-Forwarded-For header in Squid completley by using directive "forwarded_for off" or "forwarded_for delete" globally. I would like to be able to disable that header only for specific ACLs, so I can disable this header only for given URLs and have it enabled for others. Is there any way to do that?

Best Answer

You can create an ACL based on an external file to store URLs (easier to manage in my opinion) :

acl NoXForwardedFor dstdomain "/etc/squid/NoXForwardedFor.txt"

The content of /etc/squid/NoXForwardedFor.txt would be something like this :

.serverfault.com
.superuser.com
.stackoverflow.com

Then remove X-Forwarded-From from the header for the given ACL :

request_header_access X-Forwarded-For deny NoXForwardedFor

Note : You can use the dst directive instead of the dstdomain directive. But it requires URL host's IP address, so make sure the target domain has fixed ip address(es).

Maybe some useful links for deeper understanding :

Related Topic