Varnish wouldn't cache HLS fragments

Hamidreza Hosseini hrhosseini at hotmail.com
Sun Jun 13 07:15:46 UTC 2021


Hi,
I put varnish in front of my http servers to serve Hls streaming, I want varnish cache the fragments but not .m3u8 manifest file,
I configure it but it cache nothing!
My configuration file:

```
vcl 4.1;

import directors;


backend b1 {
    .host = "playback-02";
    .probe = {
        .url = "/";
        .timeout = 150 ms;
        .interval = 10s;
        .window = 6;
        .threshold = 5;
    }
}



sub vcl_init {
    # we use round robin director for our backend swift proxies

    new hls_cluster = directors.round_robin();
    hls_cluster.add_backend(b1);

}

acl purge {
    "localhost";
}


sub vcl_recv {

    set req.backend_hint = hls_cluster.backend();
    if (req.method == "PURGE") {
        if (!client.ip ~ purge) {
            return(synth(405,"Not allowed."));
        }
        return (purge);
    }

    if (req.url ~ "\.m3u8$") {
      return (pass);
    }
}





sub vcl_backend_response {
    # cache for half of a day
    set beresp.ttl=5m;
    # Don't cache 404 responses

    if (bereq.url ~ "\.(aac|dash|m4s|mp4|ts)$") {
          set beresp.ttl = 30s;
    }

    if ( beresp.status == 404 ) {
        set beresp.ttl = 120s;
        set beresp.uncacheable = true;
        return (deliver);
    }
    if (beresp.status == 500 || beresp.status == 502 || beresp.status == 503 || beresp.status == 504)
    {
        set beresp.uncacheable = true;
    }
}

```

Varnish version:
varnishd (varnish-6.0.7 revision 525d371e3ea0e0c38edd7baf0f80dc226560f26e)
Copyright (c) 2006 Verdens Gang AS
Copyright (c) 2006-2020 Varnish Software AS

Distribution: Ubuntu 20.04 LTS

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20210613/1bbce7fb/attachment.html>


More information about the varnish-misc mailing list