Hey Ragnar, welcome!
You can almost do this in Caddy 2. I need to make two small enhancements.
The proxy module can do this if the backend is down or a timeout occurs, but I’d need to make a small enhancement for it this to be doable if the origin replies with 5xx. I am currently mulling over a few design choices and then I can commit and push the best one.
The second small enhancement I’d need to make is for the cache handler to have a mode where it only inserts into the cache unless an error is returned from a later handler, in which case it could read from the cache and write a response? Or some way to use the error routes: GitHub - caddyserver/caddy: Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Can you open an issue to request this, along with your thoughts/preferences? Link to this thread. Sign in to GitHub · GitHub
Would you be willing to test this when I implement it?