Varnish is a reverse proxy, If you don’t know varnish, this article is not interesting to you π .
This is my 4 little tips that greatly optimizes the efficiency of the caching politics:
Removing tracking, this generates a single cache entry for different urls that generates the same content (I use “gclid” as a tracking argument, this is what google uses), use this as the hashing algorithm:
sub vcl_hash {
vcl.hash += regsub(req.url, β\?gclid.*β, ββ);
hash;
}
Then we can normalize compression (different browser uses different string for the “Accept-Encoding” header). Add the following in sub vcl_recv:
if (req.http.Accept-Encoding){
if (req.http.Accept-Encoding ~ "gzip"){
set req.http.Accept-Encoding = "gzip";
}elsif (req.http.Accept-Encoding ~ "deflate" ) {
set req.http.Accept-Encoding = "deflate";
}else{
remove req.http.Accept-Encoding;
;}
}
When a cookie is generated all subsequent request for any object uses that cookie, we shall remove the cookie for all static content
In sub vcl_recv add this:
if (req.url ~ "\.(js|css|jpg|png|gif|mp3|swf|flv|xml|html|ico)$"){
remove req.http.cookie;
}
Be carefull with files with these extensions that generates dynamic content (png, jpg, gif file for captcha, html with rewriteΒ to php or aspx …)
To track client ip address in the log of your web server (the real one, the backend), in sub vcl_recv add this:
remove req.http.X-Forwarded-For;
set req.http.X-Forwarded-For=client.ip;
Then you can log the “X-Forwarded-For
” header in your log (doing this depends on your webserver, I do that on apache and lighttpd).