Getting going - simplest possible setup
part1_basic.cfm
Code Block |
---|
<CFHEADER NAME="Cache-Control" VALUE="s-maxage=600">
<cfoutput>
|
...
<html>
|
...
<body>
|
...
<strong>Generated by server:</strong> #dateformat(now(),'ddd, mmm d yyyy')# #timeformat(now(),'HH:mm:ss')#<br>
|
...
<strong>Loaded by browser:</strong> <script type="text/javascript">document.write(new Date());</script>
|
...
</body>
|
...
</html>
</cfoutput> |
...
Info |
---|
|
Static assets
/etc/varnish/default.vcl
Code Block |
---|
sub vcl_recv {
if (req.url ~ "\.(jpg|jpeg|gif|png|ico|css|zip|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$") {
unset req.http.Accept-Encoding;
// Remove user agent
if (req.http.User-Agent) {
set req.http.User-Agent = "";
}
unset req.http.Cookie;
return(lookup);
}
}
|
virtual.conf
Code Block |
---|
<VirtualHost *:80>
...
# Set up caching on media files for 1 year (forever?)
<FilesMatch "\.(jpg|jpeg|gif|png|ico|css|zip|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$">
ExpiresDefault A29030400
Header append Cache-Control "public"
</FilesMatch>
</VirtualHost>
|
Info | |
---|---|
|
| |
|
Flush Varnish cache from backend
/etc/varnish/default.vcl
Code Block |
---|
// IPs/domains that can access the purge url
acl purge {
"localhost";
"117.53.174.178";
"117.53.174.179";
"203.26.11.39";
}
sub vcl_recv {
// Purge everything url - this isn't the squid way, but works
if (req.url ~ "^/varnishpurge") {
if (!client.ip ~ purge) {
error 405 "Not allowed.";
}
if (req.url == "/varnishpurge") {
ban("req.http.host == " + req.http.host + " && req.url ~ ^/");
error 841 "Purged site.";
}
else {
ban("req.http.host == " + req.http.host + " && req.url ~ ^" + regsub( req.url, "^/varnishpurge(.*)$", "\1" ) + "$" );
error 842 "Purged page.";
}
}
}
|
Info |
---|
|
Invalidate cache from client side
By IP
/etc/varnish/default.vcl
Code Block |
---|
// IPs/domains that bypass cache
acl bypass {
"1.2.3.4";
}
sub vcl_recv {
if (client.ip ~ bypass) {
return(pass);
}
}
|
Info |
---|
return(pass) passes the request to the backend |
By Cookie
/etc/varnish/default.vcl
sub vcl_recv { if (req.http.Cookie ~ "LOGGED-IN=1") { return(pass) } }
...