Squid Proxy – Configure Squid Proxy with PAC File

networkingpacPROXYsquid

So i have squid proxy server installed and running on my ec2 instance. my task is to have any pc client connected to the proxy only the proxy when accessing certain sites and will use regular wifi connection for everything else. Something like a whitelist, or only use the proxy for certain specific sites and nothing else.

Is such a thing achievable by any chance?

any help or guidance is greatly appreciated.

Cheers!

Best Answer

Yes, this is a typical PAC file usage, check the below example code:

function FindProxyForURL(url, host) {

// If the hostname matches, send to the proxy.
    if (dnsDomainIs(host, "exampldomain.com") ||
        shExpMatch(host, "(*.abcdomain.com|abcdomain.com)"))
        return "PROXY 1.2.3.4:8080";


// DEFAULT RULE: All other traffic, send direct.
    return "DIRECT";

}

dnsDomainIs and shExpMatch are two functions of checking a domain name for a match, dnsDomainIs evaluates hostnames and returns true if hostnames match. Used mainly to match and exception individual hostnames. shExpMatch will attempt to match hostname or URL to a specified shell expression, and returns true if matched.

If you would like to have the user try to connect direct if it is unable to reach the proxy, then you will need to modify this line:

return "PROXY 1.2.3.4:8080";

To be:

return "PROXY 1.2.3.4:8080; DIRECT";
Related Topic