Created
March 17, 2017 17:44
-
-
Save rezan/1c0bcb1c94f7486c4eff37e15b0dfe91 to your computer and use it in GitHub Desktop.
Varnish Extend example VCL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Varnish Extend VOD Demo | |
vcl 4.0; | |
import std; | |
import fsbackend; | |
backend default { | |
.host = "origin-frankfurt.varnish-software.com"; | |
.port = "https"; | |
.ssl = 1; | |
.ssl_nosni = 1; | |
.ssl_noverify = 1; | |
} | |
sub vcl_init { | |
new root = fsbackend.root("/var/www/html/"); | |
} | |
sub vcl_recv { | |
# Enforce HTTPS | |
if (std.port(server.ip) == 80 && req.url !~ "^/r20.gif") { | |
set req.http.x-redir = "https://" + req.http.host + req.url; | |
return(synth(302, "Found")); | |
} | |
# Forward them to the player | |
if (req.url == "/") { | |
set req.http.x-redir = "https://" + req.http.host + "/dash.js/samples/dash-if-reference-player/"; | |
return(synth(302, "Found")); | |
} | |
set req.http.Host = server.identity; | |
unset req.http.Cookie; | |
if (req.url ~ "/r20.gif") { | |
# Clean up URL | |
set req.url = "/r20.gif"; | |
set req.backend_hint = root.backend(); | |
} | |
} | |
sub vcl_synth { | |
if (resp.status == 302) { | |
set resp.http.Location = req.http.x-redir; | |
return (deliver); | |
} | |
} | |
sub vcl_backend_response{ | |
set beresp.ttl = 60m; | |
beresp.http.X-origin-hits = beresp.http.X-hits; | |
beresp.http.X-origin-host = beresp.http.X-host; | |
unset beresp.http.X-hits; | |
unset beresp.http.X-host; | |
} | |
sub vcl_deliver { | |
set resp.http.X-host = req.http.Host; | |
set resp.http.X-hits = obj.hits; | |
if (req.url != "/r20.gif") { | |
std.log("vcs-key:ALL"); | |
std.log("vcs-key:HOST/" + req.http.Host); | |
std.log("vcs-key:URL/" + req.http.Host + req.url); | |
std.log("vcs-key:CONTENT/" + req.http.Host + "/" + resp.http.Content-Type); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment