[squid-users] Howto make Squid config dependent on hostname?

Hildegard Meier daku8938 at gmx.de
Thu Sep 15 14:29:31 UTC 2022


Hello,

we have two Squid servers (Linux hosts) and each shall have the very same config file /etc/squid/squid.conf
which is versioned and deployed from a central deployment server.
So each host shall have deployed the same files.

Each of the two shall have the other configured as sibling cache peer.

So node1 shall have
cache_peer node2.examlpe.com sibling 3128 3130

and node2 shalle have
cache_peer node1.examlpe.com sibling 3128 3130

I guess it is not so nice to have both configured with both lines together, no?

cache_peer node1.examlpe.com sibling 3128 3130
cache_peer node2.examlpe.com sibling 3128 3130

With above, each node would not only have the othe node as sibling, but also itself configured as sibling, that's ugly and I do not know how squid will handle that.
I tested that, and config parser does say ok, and squid starts with that, but I find that ugly.

Does squif offer a hostname conditional if clause ?
In the docu is mentioned the squid config if-else-condition, but I did not find any example about it and what macros/variables/values one could use with it.

I think about something like this:

if $MY_HOSTNAME == 'node1' then
    cache_peer node2.examlpe.com sibling 3128 3130
fi

if $MY_HOSTNAME == 'node2' then
    cache_peer node1.examlpe.com sibling 3128 3130
fi

Best regards


More information about the squid-users mailing list