Proxy specific files only?

I’ve trying to get a specific use case workingas part of testing an external tool. I’m wondering if it’s possible ot match on a specific file extension and then proxy those requests

e.g.

mysite.com/tmp/foo.m3u8 would be delivered as expected
mysite.com/tmp/*.ts would be proxied as http://example.com/*.ts

I also attempted a rewrite

rewrite /tmp {
r ^/tmp(.*)$
to {1}
}
redir {
if {path} ends_with ts
to http://example.com/{rewrite_uri}
}
but it wasn’t working for some reason

I’ve tried variations of the rewrite/redirect combo but haven’t been successful.

Try this, for example extensions .foo and .bar:

example.com {

  # Rewrite to prepend proxy path based on ext
  rewrite /tmp {
    ext .foo .bar
    to /proxy-foo-bar{uri}
  }

  # Proxy from the specific path and strip out the prefix  
  proxy /proxy-foo-bar [upstream:port] {
    without /proxy-foo-bar/tmp
  }

}

https://caddyserver.com/docs/rewrite
https://caddyserver.com/docs/proxy

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.