0

I've several varnish cache servers (v2.1), and I'm looking to add the hostname in the headers in the response from varnish -- so I know which server is (or not) serving cached pages. Upon googling, I found this snippet, but it gives errors:

sub vcl_deliver {
  if (obj.hits > 0) {
    set resp.http.X-MH-Cache ="HIT " obj.hits " "*
    server.hostname* " " resp.http.Age;
  } else {
    set resp.http.X-MH-Cache ="MISS " *server.hostname* ""
  }
}

I am not tied to this snippet per se. Ideally, I would like to set hostname in the event of a miss or a hit.

I am fairly new to vcl files, so any guidance and assistance would be much appreciated. Many thanks!

KM

2 Answers 2

0

Stumbled upon this by chance (isn't it always that way?): https://www.varnish-cache.org/trac/wiki/VCLExampleHitMissHeader -- exactly what I was looking for.

1
  • This is not a correct answer (linking to documentation)
    – younes0
    Nov 13, 2015 at 18:56
0

More likely the error was due to the star signs, and missing plus signs when building up the "X-MH-Cache response header:

Unknown token '*' when looking for STRING

The working vcl code snippet looks like this:

vcl 4.1;
import std;
sub vcl_deliver {
  if (obj.hits > 0) {
    set resp.http.X-MH-Cache = "HIT: " + obj.hits + " *" + server.hostname + "* Age: " + resp.http.Age;
  } else {
    set resp.http.X-MH-Cache = "MISS *" + server.hostname + "*";
  }
}

A snapshot (January 2nd, 2012) to the URL from of the answer (January 27th, 2012) can be found on the Internet Archive site here: https://web.archive.org/web/20120309095329/https://www.varnish-cache.org/trac/wiki/VCLExampleHitMissHeader

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .