Skip to content

Instantly share code, notes, and snippets.

@tuklusan
Last active September 24, 2016 17:08
Show Gist options
  • Save tuklusan/205432301dbe8e5403893bbd10e1a0a3 to your computer and use it in GitHub Desktop.
Save tuklusan/205432301dbe8e5403893bbd10e1a0a3 to your computer and use it in GitHub Desktop.
/etc/varnish/default.vcl - Varnish 4 Working Simple Basic default.vcl | Simple Basic Working VARNISH 4.0 Configuration: default.vcl and varnish.params for a functional web server cache - http://supratim-sanyal.blogspot.com/2016/09/simple-basic-working-varnish-40.html
# --
# /etc/varnish/default.vcl
# Minimal working Varnish 4.0 Configuration to serve static-only website pages from lighttpd backend
# From "Simple Basic Working VARNISH 4.0 Configuration: default.vcl and varnish.params for a functional web server cache"
# http://supratim-sanyal.blogspot.com/2016/09/simple-basic-working-varnish-40.html
# --
vcl 4.0;
backend default {
.host = "127.0.0.1";
.port = "65481";
.connect_timeout = 15s;
.first_byte_timeout = 30s;
.between_bytes_timeout = 5s;
.probe = {
.request =
"HEAD / HTTP/1.1"
"Host: 127.0.0.1:65481"
"Connection: close";
.interval = 3600s; # probe backend every hour
.timeout = 15s;
.window = 40;
.threshold = 38;
.initial = 38;
}
}
sub vcl_recv {
# Uncomment if Redirecting to https.
#if (req.http.host ~ "^(?i)[wwww\.]?abadcer\.com$" && req.http.X-Forwarded-Proto != "https") {
# set req.http.x-redir = "https://" + req.http.host + req.url;
# return(synth(850, "Moved permanently"));
#}
# do not cache streams or big files for download
if (req.url ~ "^[^?]*\.(mp[34]|iso|rar|tar|tgz|gz|wav|zip|bz2|xz|7z|avi|mov|ogm|mpe?g|mk[av]|webm)(\?.*)?$") {
return (pipe);
}
# Strip off cookies in request for my static website
if (req.url ~ "(?i)\.(?:css|gif|html|ico|jpeg|jpg|js|json|png|swf|txt|woff)(?:\?.*)?$") {
unset req.http.cookie;
}
}
sub vcl_backend_response {
# Strip off cookies in response for my static website
if (bereq.url ~ "(?i)\.(?:css|gif|html|ico|jpeg|jpg|js|json|png|swf|txt|woff)(?:\?.*)?$") {
unset beresp.http.set-cookie;
}
# Enable compression on suitable content types
if (beresp.http.content-type ~ "(text|javascript|json|plain|xml)") {
set beresp.do_gzip = true;
}
# The returned content is browser-agnostic; strip any http vary indicators in the response
if (beresp.http.Vary ~ "User-Agent") {
set beresp.http.Vary = regsuball(beresp.http.Vary, ",? *User-Agent *", "");
set beresp.http.Vary = regsub(beresp.http.Vary, "^, *", "");
if (beresp.http.Vary == "") {
unset beresp.http.Vary;
}
}
# Cache expiry after an hour (The blocklist is updated every hour), but only for normal HTTP responses
if (beresp.status < 400 ) {
set beresp.ttl = 60m;
return(deliver);
}
} #end vcl_backend_response
# Corresponding to commented out https redirection condition at top
#sub vcl_synth {
# if (resp.status == 850) {
# set resp.http.Location = req.http.x-redir;
# set resp.status = 302;
# return (deliver);
# }
#}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment