Skip to content

Instantly share code, notes, and snippets.

@igorescobar
Created November 13, 2012 12:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igorescobar/4065499 to your computer and use it in GitHub Desktop.
Save igorescobar/4065499 to your computer and use it in GitHub Desktop.
Varnish Grace Mode
# /etc/varnish/default.vcl
# Define the list of backends (web servers).
# Port 80 Backend Servers
backend yourapp_webserver1 {
.host = "000.000.000.000";
.port = "80";
.max_connections = 250;
.connect_timeout = 5s;
.first_byte_timeout = 5s;
.between_bytes_timeout = 5s;
.probe = {
.url = "/";
.interval = 3s;
.timeout = 2s;
.window = 3;
.threshold = 2;
}
}
# Define the director that determines how to distribute incoming requests.
director your_app round-robin {
{ .backend = your_app_webserver1; }
}
# VCL_RECV FUNCTION
if (req.http.host ~ "your\.host\.name\.com\.br" || req.http.host == "origin.your.host.name.com.br") {
set req.backend = your_app;
# defines how long an overdue an object can be for Varnish to still consider it for grace mode
set req.grace = 24h;
}
# VCL_FETCH FUNCTION
if (req.http.host ~ "your\.host\.name\.com\.br" || req.http.host == "origin.your.host.name.com.br") {
# defines how long past the beresp.ttl-time Varnish will keep an object
set beresp.grace = 24h;
# only caches the backend response when its status is lower than 500
if (beresp.status >= 500) {
set beresp.ttl = 0s;
set beresp.cacheable = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment