Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.63 KB | None | 0 0
  1. vcl 4.0;
  2. import directors;
  3. # import tcp;
  4.  
  5. backend ott_live {
  6. .host = "xxx.xxx.xxx.100";
  7. .port = "80";
  8. .probe = {
  9. .url = "/HealthCheck.txt";
  10. .timeout = 5s;
  11. .interval = 1s;
  12. .window = 5;
  13. .threshold = 4;
  14. }
  15. }
  16.  
  17. backend ott_live2 {
  18. .host = "xxx.xxx.xxx.102";
  19. .port = "80";
  20. .probe = {
  21. .url = "/HealthCheck.txt";
  22. .timeout = 5s;
  23. .interval = 1s;
  24. .window = 5;
  25. .threshold = 4;
  26. }
  27. }
  28.  
  29. backend ott_live2_3 {
  30. .host = "xxx.xxx.xxx.21";
  31. .port = "80";
  32. .probe = {
  33. .url = "/HealthCheck.txt";
  34. .timeout = 5s;
  35. .interval = 1s;
  36. .window = 5;
  37. .threshold = 4;
  38. }
  39. }
  40.  
  41. backend ott_live3 {
  42. .host = "xxx.xxx.xxx.21";
  43. .port = "80";
  44. .probe = {
  45. .url = "/HealthCheck.txt";
  46. .timeout = 5s;
  47. .interval = 1s;
  48. .window = 5;
  49. .threshold = 4;
  50. }
  51. }
  52.  
  53. backend ott_abr_live1_1 {
  54. .host = "xxx.xxx.xxx.70";
  55. .port = "80";
  56. .probe = {
  57. .url = "/health";
  58. .timeout = 5s;
  59. .interval = 1s;
  60. .window = 5;
  61. .threshold = 4;
  62. }
  63. }
  64.  
  65. backend ott_abr_live1_2 {
  66. .host = "xxx.xxx.xxx.71";
  67. .port = "80";
  68. .probe = {
  69. .url = "/health";
  70. .timeout = 5s;
  71. .interval = 1s;
  72. .window = 5;
  73. .threshold = 4;
  74. }
  75. }
  76.  
  77. backend ott_abr_live1_3 {
  78. .host = "xxx.xxx.xxx.72";
  79. .port = "80";
  80. .probe = {
  81. .url = "/health";
  82. .timeout = 5s;
  83. .interval = 1s;
  84. .window = 5;
  85. .threshold = 4;
  86. }
  87. }
  88.  
  89. backend ott_nimble {
  90. .host = "xxx.xxx.xxx.16";
  91. .port = "8081";
  92.  
  93. }
  94.  
  95. sub vcl_init {
  96. new live2_rr = directors.round_robin();
  97. live2_rr.add_backend(ott_live2);
  98. live2_rr.add_backend(ott_live2_3);
  99. }
  100.  
  101. sub vcl_init {
  102. new abr_live_rr = directors.round_robin();
  103. abr_live_rr.add_backend(ott_abr_live1_1);
  104. abr_live_rr.add_backend(ott_abr_live1_2);
  105. abr_live_rr.add_backend(ott_abr_live1_3);
  106. }
  107.  
  108. sub vcl_hit {
  109. set req.http.X-Varnish-TTL = obj.ttl;
  110. set req.http.X-Varnish-Cache = "hit";
  111. }
  112. sub vcl_miss {
  113. set req.http.X-Varnish-TTL = 0;
  114. set req.http.X-Varnish-Cache = "miss";
  115. }
  116.  
  117. sub vcl_pass {
  118. set req.http.X-Varnish-TTL = 0;
  119. set req.http.X-Varnish-Cache = "pass";
  120. }
  121.  
  122. sub vcl_recv {
  123. if (req.http.x-forwarded-for) {
  124. set req.http.X-Forwarded-For = req.http.X-Forwarded-For;
  125. }
  126. else {
  127. set req.http.X-Forwarded-For = client.ip;
  128. }
  129.  
  130. if (req.http.host ~ "xxxx.com") {
  131. set req.backend_hint = ott_live;
  132. }
  133. elsif (req.http.host ~ "xxxx1.com") {
  134. set req.backend_hint = live2_rr.backend();
  135. unset req.http.If-Modified-Since;
  136. unset req.http.If-None-Match;
  137. }
  138. elsif (req.http.host ~ "xxxx2.com") {
  139. set req.backend_hint = live2_rr.backend();
  140. unset req.http.If-Modified-Since;
  141. unset req.http.If-None-Match;
  142. }
  143. elsif (req.http.host ~ "xxxx3.com") {
  144. set req.backend_hint = live2_rr.backend();
  145. unset req.http.If-Modified-Since;
  146. unset req.http.If-None-Match;
  147. }
  148.  
  149. elsif (req.http.host ~ "xxxx4.com") {
  150. set req.backend_hint = abr_live_rr.backend();
  151. unset req.http.If-Modified-Since;
  152. unset req.http.If-None-Match;
  153. }
  154.  
  155. elsif (req.http.host ~ "xxxx5.com") {
  156. set req.backend_hint = live2_rr.backend();
  157. unset req.http.If-Modified-Since;
  158. unset req.http.If-None-Match;
  159. }
  160.  
  161. elsif (req.http.host ~ "xxxx6.com") {
  162. set req.backend_hint = live2_rr.backend();
  163. unset req.http.If-Modified-Since;
  164. unset req.http.If-None-Match;
  165. }
  166. elsif (req.http.host ~ "xxxx7.com") {
  167. set req.backend_hint = live2_rr.backend();
  168. unset req.http.If-Modified-Since;
  169. unset req.http.If-None-Match;
  170. }
  171. elsif (req.http.host ~ "xxxx8.com") {
  172. set req.backend_hint = live2_rr.backend();
  173. unset req.http.If-Modified-Since;
  174. unset req.http.If-None-Match;
  175. }
  176. elsif (req.http.host ~ "xxxx9.como") {
  177. set req.backend_hint = live2_rr.backend();
  178. }
  179. elsif (req.http.host ~ "xxxx10.com") {
  180. set req.backend_hint = ott_live3;
  181. }
  182. elsif (req.http.host ~ "xxxx11.com") {
  183. set req.backend_hint = ott_nimble;
  184. }
  185. elsif (req.http.host ~ "xxxx12.com") {
  186. set req.backend_hint = ott_nimble;
  187. }
  188. else {
  189. return (synth(750, "Backend not found"));
  190. }
  191.  
  192. # Not really needed, but will keep for sake of confirmation
  193. if (req.url ~ "^/flu" || req.url ~ "\.ts$" || req.url ~ "Seg(\d+)-Frag(\d+)$" || req.url ~ "Fragments" ) {
  194. unset req.http.cookie;
  195. }
  196. }
  197.  
  198. sub vcl_synth {
  199. if (resp.status == 750){
  200. set resp.status = 403;
  201. set resp.http.Content-Type = "text/html; charset=utf-8";
  202. synthetic( {"
  203. <html>
  204. <head>
  205. <title>"} + resp.status + {" wrong resource requested</title>
  206. </head>
  207. <body>
  208. <h1>Error "} + resp.status + {" wrong resource requested</h1>
  209. <!--<img src=beacon750.png width=1px height=1px>-->
  210. </body>
  211. </html> "} );
  212. return (deliver);
  213. }
  214. }
  215.  
  216. sub vcl_backend_response {
  217. if (bereq.url ~ "^/flu" || bereq.url ~ "\.ts$" || bereq.url ~ "Seg(\d+)-Frag(\d+)$" || bereq.url ~ "Fragments") {
  218. if (beresp.status == 200) {
  219. unset beresp.http.set-cookie;
  220. unset beresp.http.Cache-Control;
  221. #unset beresp.http.resp.X-USP;
  222. #unset beresp.http.resp.X-USP-Info1;
  223. #unset beresp.http.resp.X-USP-Info2;
  224. unset beresp.http.Expires;
  225. set beresp.ttl = 120m;
  226. set beresp.http.Expires = "" + (now + beresp.ttl);
  227. return (deliver);
  228. }
  229. elsif (beresp.status == 412) {
  230. set beresp.ttl = 256ms;
  231. #set beresp.uncacheable = true;
  232. return (deliver);
  233. }
  234. elsif (beresp.status == 404) {
  235. set beresp.ttl = 0s;
  236. set beresp.uncacheable = true;
  237. return (deliver);
  238. }
  239. elsif (beresp.status == 304) {
  240. set beresp.ttl = 0s;
  241. set beresp.uncacheable = true;
  242. return (deliver);
  243. }
  244. elsif (beresp.status == 503) {
  245. set beresp.ttl = 0s;
  246. set beresp.uncacheable = true;
  247. return (deliver);
  248. }
  249. }
  250.  
  251. if (bereq.url ~ "(\.f4m|/Manifest|\.mpd|bootstrap)$") {
  252. set beresp.http.Cache-Control = "max-age=1";
  253. set beresp.ttl = 1s;
  254. }
  255. elsif (bereq.url ~ "(\.m3u8)$") {
  256. set beresp.http.Cache-Control = "max-age=2";
  257. set beresp.ttl = 2s;
  258. }
  259. }
  260.  
  261. sub vcl_deliver {
  262. set resp.http.X-TTL = req.http.X-Varnish-TTL;
  263. set resp.http.X-Cache = req.http.X-Varnish-Cache;
  264. unset resp.http.X-USP;
  265. unset resp.http.X-USP-Info1;
  266. unset resp.http.X-USP-Info2;
  267. unset resp.http.Via;
  268. unset resp.http.X-Varnish;
  269. unset resp.http.Age;
  270. set resp.http.X-Served-By = server.hostname;
  271. set resp.http.Server = "XXX Streaming Service";
  272. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement