Skip to content

How to use with reverse_proxy? (caching is not working) #121

@fa1rid

Description

@fa1rid

Hi, I'm trying to use Caddy to cache .m3u8 files when reverse proxying to an upstream server. I’m using the cache directive and set up my Caddyfile as follows:

{
    order cache before rewrite
    order cache before reverse_proxy
    cache {
        allowed_http_verbs GET POST
        ttl 60s
        timeout {
            backend 20s
            cache 100ms
        }
    }
}

:9991 {
    route /ch1/* {
        @m3u8_files {
            path_regexp m3u8 ^/.*\.m3u8(\?.*)?$
        }

        handle @m3u8_files {
            header +X-Custom-Header "Some Value"
        }

        cache @m3u8_files {
            ttl 60s
        }

        uri strip_prefix /ch1
        rewrite * /ChannelOne{uri}
        reverse_proxy https://upstream-host.me {
            header_up Host {http.reverse_proxy.upstream.hostport}
        }
    }
}

What’s working:

  • The X-Custom-Header is successfully added to the .m3u8 responses.
  • The reverse proxy is functioning and serving content.

What’s not working:

  • The caching doesn't seem to take effect at all. I expected .m3u8 files to be cached for 60 seconds, but every request still hits the upstream server.

Any help or guidance would be appreciated. Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions