varnishd -a addr:8001,addr:8002 -- Share same cache?

Jim Hayter jhayter at
Mon Mar 7 22:48:37 CET 2011

In my environment, port numbers may be on the request, but are not needed to respond nor should they influence the cache.  In my vcl_recv, I have the following lines:

    /* determine vhost name w/out port number */
    set req.http.newhost = regsub(, "([^:]*)(:.*)?$", "\1");
    set = req.http.newhost;

This strips off the port number from the host name in the request.  Doing it this way, the port number is discarded and NOT passed on to the application.  It is also not present when creating and looking up hash entries.  

If you require the port number at the application level, you will have to do something a bit different to preserve it.


-----Original Message-----
From: varnish-misc-bounces at [mailto:varnish-misc-bounces at] On Behalf Of Shenton, Chris (HQ-LM020)[INDYNE INC]
Sent: Monday, March 07, 2011 4:37 PM
To: varnish-misc at
Subject: varnishd -a addr:8001,addr:8002 -- Share same cache?

To accommodate our hosting environment, we need to run varnish on two different ports, but we want to make both use the same cache.  That is, if I have:

  varnishd -a,

I want client requests to both both 8001 and 8002 ports to share the content of the same cache. So if one client hits :8002 with a URL and another later hits :8001 with the same URL, I want the latter to retrieve the content cached by the former request.

In my testing, however, it seems that this is not happening, that the doc is getting cached once per varnishd port.

First on 8001, we see it's not from cache as this is the first request:

> $ curl -v  -o /dev/null http://localhost:8001/ 2>&1 | grep X-Varnish:
> < X-Varnish: 730421263

Then to 8002 where I'd hope it was returned from cache, but the X-Varnish and Age headers indicate it's not:

> $ curl -v  -o /dev/null http://localhost:8002/ 2>&1 | grep X-Varnish:
> < X-Varnish: 730421264

Now back to the first port, 8001, and we see it is in fact returned from cache:

> $ curl -v  -o /dev/null http://localhost:8001/ 2>&1 | grep X-Varnish:
> < X-Varnish: 730421265 730421263

And if I try 8002 again, it's also returned from cache:

> $ curl -v  -o /dev/null http://localhost:8002/ 2>&1 | grep X-Varnish:
> < X-Varnish: 730421266 730421264

Is there a way to make both ports share the same hash? I'm guessing the listening port is included with the hash key so that's why it appears each URL is being stored separately.  If so, is there a way to remove the listening port from the hash key the document is stored under? Or would that even work? 


varnish-misc mailing list
varnish-misc at

More information about the varnish-misc mailing list