Wednesday, June 10, 2009

Squid Proxy server, Ads blocking

I added an ad-blocking component to squid, not a third-party product, just a few configs of my own. The way I've implemented it, you don't see any "AD BLOCKED" crap on your webpages, you just have a clear block where the ad was, with no error message, increasing the "look/feel" experience for your users.

First, in the ACL section, create the ACL for ads:

acl ads_block_list dstdomain -i "/usr/local/etc/squid/blocks/ads_block.list"

Above all your normal http_access/http_deny rules, place this one:

deny_info ERR_BLOCKED_ADS ads_block_list
http_access deny ads_block_list

Now, create the file /usr/local/etc/squid/blocks/ads_block.list and populate it (I've just shown a head from my file):

[root@nas /usr/local/etc/squid/blocks]# head ads_block.list

You can get anti-ads lists such as mine from various locations, use google to search.

Now edit the custom error message for the ads_block_list ACL, which is: ERR_BLOCKED_ADS

[root@nas /usr/local/etc/squid/errors/English]# cat ERR_BLOCKED_ADS

That last line, you'll notice the ! character which means don't display the standard squid error message.

once all is complete, reload your configs with "squid - k reconfigure" and try access pages now. Ads are blocked, and all you see is the page background. This way you can save large amounts of bandwidth on your internet lines, without creating errors or graphical problems on user viewed pages.

1 comment: