Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vcl 4.0;
- import directors;
- # import tcp;
- backend ott_live {
- .host = "xxx.xxx.xxx.100";
- .port = "80";
- .probe = {
- .url = "/HealthCheck.txt";
- .timeout = 5s;
- .interval = 1s;
- .window = 5;
- .threshold = 4;
- }
- }
- backend ott_live2 {
- .host = "xxx.xxx.xxx.102";
- .port = "80";
- .probe = {
- .url = "/HealthCheck.txt";
- .timeout = 5s;
- .interval = 1s;
- .window = 5;
- .threshold = 4;
- }
- }
- backend ott_live2_3 {
- .host = "xxx.xxx.xxx.21";
- .port = "80";
- .probe = {
- .url = "/HealthCheck.txt";
- .timeout = 5s;
- .interval = 1s;
- .window = 5;
- .threshold = 4;
- }
- }
- backend ott_live3 {
- .host = "xxx.xxx.xxx.21";
- .port = "80";
- .probe = {
- .url = "/HealthCheck.txt";
- .timeout = 5s;
- .interval = 1s;
- .window = 5;
- .threshold = 4;
- }
- }
- backend ott_abr_live1_1 {
- .host = "xxx.xxx.xxx.70";
- .port = "80";
- .probe = {
- .url = "/health";
- .timeout = 5s;
- .interval = 1s;
- .window = 5;
- .threshold = 4;
- }
- }
- backend ott_abr_live1_2 {
- .host = "xxx.xxx.xxx.71";
- .port = "80";
- .probe = {
- .url = "/health";
- .timeout = 5s;
- .interval = 1s;
- .window = 5;
- .threshold = 4;
- }
- }
- backend ott_abr_live1_3 {
- .host = "xxx.xxx.xxx.72";
- .port = "80";
- .probe = {
- .url = "/health";
- .timeout = 5s;
- .interval = 1s;
- .window = 5;
- .threshold = 4;
- }
- }
- backend ott_nimble {
- .host = "xxx.xxx.xxx.16";
- .port = "8081";
- }
- sub vcl_init {
- new live2_rr = directors.round_robin();
- live2_rr.add_backend(ott_live2);
- live2_rr.add_backend(ott_live2_3);
- }
- sub vcl_init {
- new abr_live_rr = directors.round_robin();
- abr_live_rr.add_backend(ott_abr_live1_1);
- abr_live_rr.add_backend(ott_abr_live1_2);
- abr_live_rr.add_backend(ott_abr_live1_3);
- }
- sub vcl_hit {
- set req.http.X-Varnish-TTL = obj.ttl;
- set req.http.X-Varnish-Cache = "hit";
- }
- sub vcl_miss {
- set req.http.X-Varnish-TTL = 0;
- set req.http.X-Varnish-Cache = "miss";
- }
- sub vcl_pass {
- set req.http.X-Varnish-TTL = 0;
- set req.http.X-Varnish-Cache = "pass";
- }
- sub vcl_recv {
- if (req.http.x-forwarded-for) {
- set req.http.X-Forwarded-For = req.http.X-Forwarded-For;
- }
- else {
- set req.http.X-Forwarded-For = client.ip;
- }
- if (req.http.host ~ "xxxx.com") {
- set req.backend_hint = ott_live;
- }
- elsif (req.http.host ~ "xxxx1.com") {
- set req.backend_hint = live2_rr.backend();
- unset req.http.If-Modified-Since;
- unset req.http.If-None-Match;
- }
- elsif (req.http.host ~ "xxxx2.com") {
- set req.backend_hint = live2_rr.backend();
- unset req.http.If-Modified-Since;
- unset req.http.If-None-Match;
- }
- elsif (req.http.host ~ "xxxx3.com") {
- set req.backend_hint = live2_rr.backend();
- unset req.http.If-Modified-Since;
- unset req.http.If-None-Match;
- }
- elsif (req.http.host ~ "xxxx4.com") {
- set req.backend_hint = abr_live_rr.backend();
- unset req.http.If-Modified-Since;
- unset req.http.If-None-Match;
- }
- elsif (req.http.host ~ "xxxx5.com") {
- set req.backend_hint = live2_rr.backend();
- unset req.http.If-Modified-Since;
- unset req.http.If-None-Match;
- }
- elsif (req.http.host ~ "xxxx6.com") {
- set req.backend_hint = live2_rr.backend();
- unset req.http.If-Modified-Since;
- unset req.http.If-None-Match;
- }
- elsif (req.http.host ~ "xxxx7.com") {
- set req.backend_hint = live2_rr.backend();
- unset req.http.If-Modified-Since;
- unset req.http.If-None-Match;
- }
- elsif (req.http.host ~ "xxxx8.com") {
- set req.backend_hint = live2_rr.backend();
- unset req.http.If-Modified-Since;
- unset req.http.If-None-Match;
- }
- elsif (req.http.host ~ "xxxx9.como") {
- set req.backend_hint = live2_rr.backend();
- }
- elsif (req.http.host ~ "xxxx10.com") {
- set req.backend_hint = ott_live3;
- }
- elsif (req.http.host ~ "xxxx11.com") {
- set req.backend_hint = ott_nimble;
- }
- elsif (req.http.host ~ "xxxx12.com") {
- set req.backend_hint = ott_nimble;
- }
- else {
- return (synth(750, "Backend not found"));
- }
- # Not really needed, but will keep for sake of confirmation
- if (req.url ~ "^/flu" || req.url ~ "\.ts$" || req.url ~ "Seg(\d+)-Frag(\d+)$" || req.url ~ "Fragments" ) {
- unset req.http.cookie;
- }
- }
- sub vcl_synth {
- if (resp.status == 750){
- set resp.status = 403;
- set resp.http.Content-Type = "text/html; charset=utf-8";
- synthetic( {"
- <html>
- <head>
- <title>"} + resp.status + {" wrong resource requested</title>
- </head>
- <body>
- <h1>Error "} + resp.status + {" wrong resource requested</h1>
- <!--<img src=beacon750.png width=1px height=1px>-->
- </body>
- </html> "} );
- return (deliver);
- }
- }
- sub vcl_backend_response {
- if (bereq.url ~ "^/flu" || bereq.url ~ "\.ts$" || bereq.url ~ "Seg(\d+)-Frag(\d+)$" || bereq.url ~ "Fragments") {
- if (beresp.status == 200) {
- unset beresp.http.set-cookie;
- unset beresp.http.Cache-Control;
- #unset beresp.http.resp.X-USP;
- #unset beresp.http.resp.X-USP-Info1;
- #unset beresp.http.resp.X-USP-Info2;
- unset beresp.http.Expires;
- set beresp.ttl = 120m;
- set beresp.http.Expires = "" + (now + beresp.ttl);
- return (deliver);
- }
- elsif (beresp.status == 412) {
- set beresp.ttl = 256ms;
- #set beresp.uncacheable = true;
- return (deliver);
- }
- elsif (beresp.status == 404) {
- set beresp.ttl = 0s;
- set beresp.uncacheable = true;
- return (deliver);
- }
- elsif (beresp.status == 304) {
- set beresp.ttl = 0s;
- set beresp.uncacheable = true;
- return (deliver);
- }
- elsif (beresp.status == 503) {
- set beresp.ttl = 0s;
- set beresp.uncacheable = true;
- return (deliver);
- }
- }
- if (bereq.url ~ "(\.f4m|/Manifest|\.mpd|bootstrap)$") {
- set beresp.http.Cache-Control = "max-age=1";
- set beresp.ttl = 1s;
- }
- elsif (bereq.url ~ "(\.m3u8)$") {
- set beresp.http.Cache-Control = "max-age=2";
- set beresp.ttl = 2s;
- }
- }
- sub vcl_deliver {
- set resp.http.X-TTL = req.http.X-Varnish-TTL;
- set resp.http.X-Cache = req.http.X-Varnish-Cache;
- unset resp.http.X-USP;
- unset resp.http.X-USP-Info1;
- unset resp.http.X-USP-Info2;
- unset resp.http.Via;
- unset resp.http.X-Varnish;
- unset resp.http.Age;
- set resp.http.X-Served-By = server.hostname;
- set resp.http.Server = "XXX Streaming Service";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement