Varnish Purge - Ban, custom hash
Dridi Boukelmoune
dridi.boukelmoune at zenika.com
Wed Nov 13 17:14:15 CET 2013
Hi,
Have you solved your issue ?
I haven't looked closely at the VCL yet but maybe I could help.
Dridi
On Mon, Oct 28, 2013 at 8:34 PM, Lane, Richard <rlane at ahbelo.com> wrote:
> I am using multiple hash_data calls to customize the hash key. I need to
> cache potentially three different version of the page.
>
> My problem is how do I purge the items. I have tried implementing purge; in
> recv, hit, miss functions like Varnish docs show but still not working.
>
> I have tried implementing ban using a regex or == on the URL.
>
> Below is my VCL hash function. How do I purge a URL that is hashed with
> key...
>
> "/mysection/mystory.htmlwww.example.com_preview_mobile"
>
> I had this working prior to Varnish 3 but seems to have stopped working
> after that.
>
> ##VCL Hash function below
>
> vcl_hash {
>
> hash_data(req.url);
> if (req.http.host) {
> hash_data(req.http.host);
> } else {
> hash_data(server.ip);
> }
>
> #if(req.http.Accept-Encoding) {
> # set req.hash += req.http.Accept-Encoding;
> #}
>
> ## /* Normalize Accept-Encoding to reduce effects of Vary:
> Accept-Encoding
> ## (cf. http://varnish-cache.org/wiki/FAQ/Compression)
> ## Also note that Vary: User-Agent is considered harmful */
> if (req.http.Accept-Encoding) {
> if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") {
> // Don't compress already-compressed files
> remove req.http.Accept-Encoding;
> }
> elsif (req.http.Accept-Encoding ~ "gzip") {
> set req.http.Accept-Encoding = "gzip";
> }
> elsif (req.http.Accept-Encoding ~ "deflate") {
> set req.http.Accept-Encoding = "deflate";
> }
> else {
> // unknown algorithm
> remove req.http.Accept-Encoding;
> }
> }
>
> if(req.http.x-preview == "yes" && (req.url ~ ".shtml" || req.url ~
> ".html") )
> {
> hash_data("_preview");
> ##Add device view to hash
> hash_data("_" + req.http.x-preferred-device);
>
> }else{
>
> ##Add device view to hash
> hash_data("_" + req.http.x-device);
> }
> return (hash);
> }
>
> #Purge pieces
> vcl_recv {
>
> if (req.request == "PURGE") {
> if (!client.ip ~ localaddr) {
> error 405 "Method not allowed";
> }
> ban("obj.http.x-url ~ " + req.url + " && obj.http.x-host == "
> + req.http.host + " && obj.http.x-pd ~ .*" );
> std.log("Purge : yes really purge.");
> return(lookup);
> }
>
> vcl_hit {
> if (req.request == "PURGE") {
> purge;
> error 200 "Purged.";
> }
> }
>
> vcl_miss {
> if (req.request == "PURGE") {
> purge;
> error 200 "Purged.";
> }
>
> vcl_fetch {
> #setup for banning
> set beresp.http.x-url = req.url;
> set beresp.http.x-host = req.http.host;
> set beresp.http.x-pd = req.http.x-device;
>
> }
>
> vcl_deliver {
> #Clean up banning
> unset resp.http.x-url;
> unset resp.http.x-host;
> unset resp.http.x-pd;
>
> }
>
> Thanks in advance,
>
> Richard
>
> _______________________________________________
> varnish-misc mailing list
> varnish-misc at varnish-cache.org
> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
More information about the varnish-misc
mailing list