Search code examples
proxyconditional-statementssquid

Squid conditional selection of parent proxy


Is there a way to configure the Squid proxy server in order to make it select a different parent proxy (specified by the cache_peer directive) based on the hostname in the requested URL, say in the outgoing HTTP(S) request?

For example, if the requested URL contains *.example1.com then select proxy1.host. If it contains *.example2.com and *.example3.com then select proxy2.host.


Solution

  • yes

    the directives you'll need are

    acl example1 dstdomain example1
    acl example2 dstdomain example2
    cache_peer proxy1.host parent 3128 0 no-query default
    cache_peer proxy2.host parent 3128 0 no-query default
    cache_peer_access proxy1.host allow example1
    cache_peer_access proxy2.host allow example2
    

    You might also want to know how these directives work

    never_direct
    always_direct