Paolo Alvarado Customer Support Engineer, Fastly at Altitude 2016
Customer Support Engineer Paolo Alvarado discusses various useful features of advanced Varnish Configuration Language (VCL).
8. “File not found” restart in fetch
vcl_fetch {
if (beresp.status == 404 && req.restarts == 0) {
restart;
}
#FASTLY FETCH
…}
^ if the origin response = 404 then restart.
Restart – resets the vcl state machine (back to recv)
vcl_recv
vcl_hash
vcl_fetch
10. Catch the restart
vcl_recv
vcl_hash
vcl_fetch
vcl_recv {
if (req.restarts > 0) {
set req.backend = F_secondary;
set req.http.Fastly-Force-Shield = "1";
return(lookup);
}
#FASTLY RECV
…}
^ if we restarted, switch backends, re-enable clustering, and
lookup the content
17. Creating new headers in deliver
set req.http.OrigHost = req.http.host;
set req.http.OrigURL = req.url;
^ stores the initial request’s host and url into headers
that we can use later
vcl_recv
vcl_hash
vcl_deliver
vcl_fetch
18. Use regex
set req.url =
regsub(resp.http.Location,"^https?://
[^/]+(.*)","1");
^ pulls out /path/* from www.example.com/path/*
27. Learning VCL
We have plenty to offer:
Check out our Docs page: https://docs.fastly.com/guides/vcl/
Send questions to support@fastly.com
#fastly in irc.freenode.net