Add fallback to dynamic reverse proxy using admin api

1. Caddy version (caddy version):

v2.4.4 h1:QBsN1jXEsCqRpKPBb8ebVnBNgPxwL50HINWWTuZ7evU=

2. How I run Caddy:

a. System environment:

Custom docker image built off of

d. My complete Caddyfile or JSON config:

  "apps": {
    "http": {
      "servers": {
        "sirtunnel": {
          "listen": [":443"],
          "routes": [

3. The problem I’m having:

Everything is running fine, I just have a question to make it even better;

I’m setting up Caddy as an automated reverse proxy with the aid of ssh tunneling, which is working great so far. The only “issue” I currently have, that when I register a route, but the process that actually serves the project is offline (either temporary or permanently) the 502 Caddy gives back is rather ugly.

I was wonder if it’s possible to add a fallback handler to routes that are unreachable by Caddy to present the user with something more clear than a 502 generated by the browser.

The logic I use to register the tunnel can be found here
This runs whenever a new ssh tunnel is created.

I was trying to simply add another object in the "handle" array, to server a static response with “This tunnel is currently unavailable”, but apparently it’s not that simple or I’m missing something :stuck_out_tongue:

I did find this

But I’m not really sure how to apply this in my situation, like how do I add this to the API request, or my (very empty) json config or otherwise?

If I understand what you’re trying to do, I think you’re looking for errors routes in the HTTP server. See JSON Config Structure - Caddy Documentation. The Caddyfile equivalent is handle_errors

If you’re having trouble writing the JSON, I recommend writing it with the Caddyfile first, then running caddy adapt --pretty to see what the JSON for it looks like.

That pointed me in the direction I needed to go!

Thank you very much!

The aforementioned github repository has been updated to reflect the, now working, changes.

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