← Back to post

Edit history

Most recent

In my case I have defined a fallback in Caddy so any request that doesn’t match one of the explicitly handled domains will be an error.

I use a route {} block with handle {} blocks inside it, and the last handle has an error directive in it.

https://*.example.com {
  route {
    @foo host "foo.example.com"
    handle @foo {
      reverse_proxy http://whatever:12334/
    }
    ... more proxy hosts ...
    handle {
      error 400
    }
  }
}

The route block is essential here because handlers inside a route block are processed strictly in the order they are defined. Outside route blocks that is not true, caddy will try to optimize and can execute directives in any order it sees fit.

Edited

In my case I have defined a fallback in Caddy so any request that doesn’t match one of the explicitly handled domains will be an error.

I use a route {} block with handle {} blocks inside it, and the last handle has an error directive in it.

https://*.example.com {
  route {
    @foo host "foo.example.com"
    handle @foo {
      reverse_proxy http://whatever:12334/
    }
    ... more proxy hosts ...
    handle {
      error 400
    }
  }
}
Original

In my case I have defined a fallback in Caddy so any request that doesn’t match one of the explicitly handled domains will be an error.

I use a route {} block with handle {} blocks inside it, and the last handle has an error directive in it.

https://*.example.com:443 {
  route {
    @foo host "foo.example.com"
    handle @foo {
      reverse_proxy http://whatever:12334/
    }
    ... more proxy hosts ...
    handle {
      error 400
    }
  }
}