Proxy specific files only?


(Graeme Merrall) #1

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.


(Matthew Fay) #2

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