vanish.vcl 816 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. vcl 4.0;
  2. backend default {
  3. .host = "localhost";
  4. .port = "8080";
  5. }
  6. sub vcl_recv {
  7. # Implementing websocket support (https://www.varnish-cache.org/docs/4.0/users-guide/vcl-example-websockets.html)
  8. if (req.http.Upgrade ~ "(?i)websocket") {
  9. return (pipe);
  10. }
  11. }
  12. sub vcl_pipe {
  13. if (req.http.upgrade) {
  14. set bereq.http.upgrade = req.http.upgrade;
  15. set bereq.http.connection = req.http.connection;
  16. }
  17. }
  18. sub vcl_backend_response {
  19. # Set 1s ttl if origin response HTTP status code is anything other than 200
  20. if (beresp.status != 200) {
  21. set beresp.ttl = 1s;
  22. set beresp.uncacheable = true;
  23. return (deliver);
  24. }
  25. if (bereq.url ~ "m3u8") {
  26. # assuming chunks are 2 seconds long
  27. set beresp.ttl = 1s;
  28. set beresp.grace = 0s;
  29. }
  30. if (bereq.url ~ "ts") {
  31. set beresp.ttl = 10m;
  32. set beresp.grace = 5m;
  33. }
  34. }