Skip to content

Instantly share code, notes, and snippets.

@kevincupp
Last active August 29, 2015 14:17
Show Gist options
  • Save kevincupp/253b3befc98d6ecce169 to your computer and use it in GitHub Desktop.
Save kevincupp/253b3befc98d6ecce169 to your computer and use it in GitHub Desktop.
Varnish 4.0
# sudo chmod -R 777 /usr/local/var/varnish
# To start, need to specify the port you'd like Varnish to run on if not on port 80:
# sudo ./varnishd -a 127.0.0.1:8080 -f /usr/local/etc/varnish/ee.vcl -s malloc,200M
vcl 4.0;
backend default {
.host = "127.0.0.1"; # IP address of your backend (Apache, nginx, etc.)
.port = "80"; # Port your backend is listening on
.probe = {
.url = "/";
.timeout = 1000ms;
.interval = 1s;
.window = 10;
.threshold = 8;
}
}
sub vcl_recv {
# Forward client's IP to backend
unset req.http.X-Forwarded-For;
set req.http.X-Forwarded-For = client.ip;
# Set the URI of your system directory
if (req.url ~ "^/system/" ||
req.url ~ "ACT=" ||
req.method == "POST" ||
(req.url ~ "member_box" && req.http.Cookie ~ "exp_sessionid"))
{
return (pass);
}
unset req.http.Cookie;
# This is different, read this: https://www.varnish-software.com/blog/grace-varnish-4-stale-while-revalidate-semantics-varnish
# set req.grace = 1h;
return(hash);
}
sub vcl_backend_response {
# Enable ESI includes
set beresp.do_esi = true;
# Our cache TTL
set beresp.ttl = 1m;
# set beresp.grace = 1h;
return(deliver);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment