Comment purger un élément de vos reverse proxy cache SQUID

L’utilisation d’un étage de cache web dans l’architecture d’une plate-forme d’hébergement est de plus en plus courante. Dans le cas de eZ Publish c’est même nécessaire si vous l’utilisé comme CMS générateur de site web [1].

Mais j’ai eu l’occasion de souligner l’intérêt d’un cache web à la lumière de mon actualité professionnel que cela soit quand Voici.fr dépasse les 650 K pages vue en 24h, quand Voici.fr et Gala.Fr ont survécu au pic d’audience du à la mort de Michael Jackson ou enfin quand l’optimisation d’un site eZ Publish 4 pour l’utilisation des caches web en prenant voici.fr en exemple.

Autorisé la purge dans squid.conf

Avant tout, il est nécessaire de modifier Squid via le fichier de configuration squid.conf afin d’autoriser la purge. Pour j’ai ajoutez les ligne suivantes dans ma configuration afin d’autorisé la purge depuis le squid et surtout depuis le réseau local afin que cela soit possible de toute les machines de l’architecture.

acl purge method PURGE http_access allow PURGE localnet http_access allow PURGE localhost

Purger squid avec cURL

Exemple pour purger une page du cache de trois serveurs SQUID avec cURL

~$ curl -I -X PURGE -H <span style="color: #ff0000;">&quot;Host: &lt;HOST&gt;&quot;</span> http:<span style="color: #000000; font-weight: bold;">//</span>squid<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span>,<span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/&lt;</span>URI<span style="color: #000000; font-weight: bold;">&gt;</span>

Dans cet exemple nous allons supprimé la home page de http://www.femmeactuelle.fr/ (soit l’index) actuellement mise en cache sur nos trois serveurs reverse proxy squid :

~$ curl -I -X PURGE -H <span style="color: #ff0000;">&quot;Host: www.femmeactuelle.fr&quot;</span> http:<span style="color: #000000; font-weight: bold;">//</span>squid<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span>,<span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span> HTTP<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.0</span> <span style="color: #000000;">200</span> OK Server: squid<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2.6</span>.STABLE5 Date: Fri, <span style="color: #000000;">30</span> Jan <span style="color: #000000;">2009</span> <span style="color: #000000;">10</span>:<span style="color: #000000;">35</span>:<span style="color: #000000;">26</span> GMT Content-Length: <span style="color: #000000;">0</span> &nbsp; HTTP<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.0</span> <span style="color: #000000;">200</span> OK Server: squid<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2.6</span>.STABLE5 Date: Fri, <span style="color: #000000;">30</span> Jan <span style="color: #000000;">2009</span> <span style="color: #000000;">10</span>:<span style="color: #000000;">35</span>:<span style="color: #000000;">26</span> GMT Content-Length: <span style="color: #000000;">0</span> &nbsp; HTTP<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.0</span> <span style="color: #000000;">200</span> OK Server: squid<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2.6</span>.STABLE5 Date: Fri, <span style="color: #000000;">30</span> Jan <span style="color: #000000;">2009</span> <span style="color: #000000;">10</span>:<span style="color: #000000;">35</span>:<span style="color: #000000;">26</span> GMT Content-Length: <span style="color: #000000;">0</span>

Dans cet exemple nous avons voulu supprimer la page « cachée » de http://365.femmeactuelle.fr/ (soit l’index) Toutefois aucune page n’était présente dans le cache

~$ curl -I -X PURGE -H <span style="color: #ff0000;">&quot;Host: www2.femmeactuelle.fr&quot;</span> http:<span style="color: #000000; font-weight: bold;">//</span>squid<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span>,<span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span> HTTP<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.0</span> <span style="color: #000000;">404</span> Not Found Server: squid<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2.6</span>.STABLE5 Date: Fri, <span style="color: #000000;">30</span> Jan <span style="color: #000000;">2009</span> <span style="color: #000000;">10</span>:<span style="color: #000000;">35</span>:<span style="color: #000000;">45</span> GMT Content-Length: <span style="color: #000000;">0</span> &nbsp; HTTP<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.0</span> <span style="color: #000000;">404</span> Not Found Server: squid<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2.6</span>.STABLE5 Date: Fri, <span style="color: #000000;">30</span> Jan <span style="color: #000000;">2009</span> <span style="color: #000000;">10</span>:<span style="color: #000000;">35</span>:<span style="color: #000000;">45</span> GMT Content-Length: <span style="color: #000000;">0</span> &nbsp; HTTP<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.0</span> <span style="color: #000000;">404</span> Not Found Server: squid<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2.6</span>.STABLE5 Date: Fri, <span style="color: #000000;">30</span> Jan <span style="color: #000000;">2009</span> <span style="color: #000000;">10</span>:<span style="color: #000000;">35</span>:<span style="color: #000000;">45</span> GMT Content-Length: <span style="color: #000000;">0</span>

Purger squid avec squidclient

La même chose est possible avec squidclient

<span style="color: #808080; font-style: italic;"># squidclient -m PURGE -p 80 -h prpsquid1 http://www.femmeactuelle.fr/</span>

L’utilisation de « {1,2,3} » n’est pas possible, il faut utiliser une boucle bash :

~$ <span style="color: #000000; font-weight: bold;">for</span> I <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000;">1</span> <span style="color: #000000;">2</span> <span style="color: #000000;">3</span>; <span style="color: #000000; font-weight: bold;">do</span> squidclient -m PURGE -p <span style="color: #000000;">80</span> -h squid<span style="color: #007800;">$I</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.femmeactuelle.fr<span style="color: #000000; font-weight: bold;">/</span>; <span style="color: #000000; font-weight: bold;">done</span> HTTP<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.0</span> <span style="color: #000000;">200</span> OK Server: squid<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2.6</span>.STABLE5 Date: Fri, <span style="color: #000000;">30</span> Jan <span style="color: #000000;">2009</span> <span style="color: #000000;">10</span>:<span style="color: #000000;">56</span>:<span style="color: #000000;">11</span> GMT Content-Length: <span style="color: #000000;">0</span> &nbsp; HTTP<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.0</span> <span style="color: #000000;">200</span> OK Server: squid<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2.6</span>.STABLE5 Date: Fri, <span style="color: #000000;">30</span> Jan <span style="color: #000000;">2009</span> <span style="color: #000000;">10</span>:<span style="color: #000000;">56</span>:<span style="color: #000000;">11</span> GMT Content-Length: <span style="color: #000000;">0</span> &nbsp; HTTP<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.0</span> <span style="color: #000000;">200</span> OK Server: squid<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2.6</span>.STABLE5 Date: Fri, <span style="color: #000000;">30</span> Jan <span style="color: #000000;">2009</span> <span style="color: #000000;">10</span>:<span style="color: #000000;">56</span>:<span style="color: #000000;">11</span> GMT Content-Length: <span style="color: #000000;">0</span>

Notes

[1] eZ n’est forcement utilisé comme générateur de site web. Il est avant tout un CMS; quelque soit la destination du contenu

Laisser un commentaire