Caddy 2 reverse_proxy to path

In Caddy 1, we were able to use

proxy /

To reverse to a host+path.

I encountered the same error as this issue:

But I couldn’t understand the conclusion of the issue.

My use case is the following. I have a an Object Storage/S3 bucket at OVH. It is available at this URL:<id>/mstdn-media

An object is available at:<id>/mstdn-media/file.jpg

With this config for

proxy /<id>

The users of my app were able to access it as

With Caddy 2, I can’t specify a pass for reverse_proxy.

With this:


My Caddy will proxy file.jpg to

and not<id>/mstdn-media/file.jpg

The /v1/<id> is missing and <id> has to stay private so I can’t update my app to add it in the user-facing URL: Caddy has to add it.

Is there a directive for Caddy 2 that allows me to do that? rewrite maybe? I searched the documentation but couldn’t find anything.


Yep, to add a prefix, all you need is to do a rewrite like this:

rewrite * /v1/<id>{uri}

You might need to use a matcher if you have other things being handled by the same site block. You didn’t post a full Caddyfile so I won’t try to make any assumptions here other than you’re only proxying in that site block.

1 Like

Perfect! This is exactly what I was looking for. Seems much more elegant than the Caddy 1 way.

Here is my Caddyfile for reference: {
  import ../snippets/tls.conf
  encode zstd gzip
  log {
    output file /var/log/caddy/
  rewrite * /v1/<id>{uri}
1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.