Strange different behavior

Poul-Henning Kamp phk at phk.freebsd.dk
Fri Jan 15 10:19:01 CET 2010


In message <20100114215025.GB9573 at kjeks.kristian.int>, Kristian Lyngstol writes
:

>Vary on User-Agent is generally bad, and you should Just Fix That [tm].

Apart from the compatibility issue, a secondary reason it is a bad
idea, is that User-Agent is practically unique for every single PC
in the world, so you will cache up to hundreds of copies of the pages
for no good reason.

If your site is running live on Varnish, try running:

	varnishtop -i rxheader -I User-Agent

and see how many different strings your clients send you...

In all likelyhood, your backend looks at only one or two of the bits
in User-Agent (MSIE or Mozilla ?) but Varnish has to look at the
entire string, since it has no way of knowing what your backend
looks at.

One workaround, is to do what we call "User-Agent-Washing", where
Varnish rewrites the Useragent to the handfull of different variants
your backend really cares about, along the lines of:

sub vcl_recv {
	if (req.http.user-agent ~ "MSIE") {
		set req.http.user-agent = "MSIE";
	} else {
		set req.http.user-agent = "Mozilla";
	}
}

So that you only cache the relevant number of copies.

But as Kristian says:  The best thing, is to not Vary on User-Agent
in the first place, that's how the InterNet is supposed to work.

Poul-Henning

-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.



More information about the varnish-misc mailing list