1. Caddy version (caddy version
):
v2.4.3 h1:Y1FaV2N4WO3rBqxSYA8UZsZTQdN+PwcoOcAiZTM8C0I=
2. How I run Caddy:
caddy run
a. System environment:
MacOS 11.5.2
b. Command:
caddy run
d. My complete Caddyfile or JSON config:
:2016
@matcher_front {
header_regexp host Host ^front
}
reverse_proxy @matcher_front 127.0.0.1:3000 127.0.0.1:8080 {
lb_policy first
@error status 500 502 503
handle_response @error {
reverse_proxy * 127.0.0.1:8080
}
}
3. The problem I’m having:
What I’m trying to achieve, is having a fallback URL for one of my proxy servers. I have a route that matches correctly to my local :3000 port. However if that service is not up, I’d like the request to be forward to a different service at port :8080 which will run some logic and then will start-up the service at :3000.
4. Error messages and/or full log output:
This is what gets logged when I make a request with my service on 3000 down:
2021/08/24 02:53:41.822 ERROR http.log.error dial tcp 127.0.0.1:3000: connect: connection refused {"request": {"remote_addr": "127.0.0.1:52749", "proto": "HTTP/1.1", "method": "GET", "host": "front:2016", "uri": "/", "headers": {"Upgrade-Insecure-Requests": ["1"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Accept-Encoding": ["gzip, deflate"], "Connection": ["keep-alive"], "Pragma": ["no-cache"], "Cache-Control": ["no-cache"], "User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"], "Accept-Language": ["en-US,en;q=0.9"]}}, "duration": 0.000322875, "status": 502, "err_id": "08gevucx1", "err_trace": "reverseproxy.statusError (reverseproxy.go:857)"}
5. What I already tried:
I tried adding the :8080 as another upstream to my reverse_proxy list, with first
as the strategy, hoping if the first one is down it’ll just hit the 8080 instead, but that didn’t work.
I also tried using the handle_response, to route there, but that also doesn’t get called (I assume because there’s no status code)
I’m very new to caddy, and just going off the docs. Can this be done?