My environment is as follows.
I have an HTTP-service, that can tell if it’s working or not. It does so by responding on a POST requests, i.e.
- I send
curl -X POST --data '{ jsonrpc ..., "method":alive' }
- And response contains
"alive": true
So, I have several instances of that HTTP service, and I want to load balance (fail over, actually) between them. So I came up with the following config:
http://balancer:1234 {
proxy / http://instance1:1234 http://instance2:1234 {
policy first
fail_timeout 1m
max_fails 3
try_duration 5s
health_check /
health_check_port 1234
health_check_contains ''"alive":true'
transparent
}
}
But it doesn’t work, as it sends HTTP GET, and receives HTTP OK with an empty body.
So I’m looking for a way to make this work. One idea I came up with is to define another caddy endpoint that will take a GET from health check, convert it to POST, send to a service, and return response body. In my imaginations, it could look something like that:
http://instance1:5678 {
proxy / {
verb POST
content '{ jsonrpc ..., "method":alive' }'
}
}
http://balancer:1234 {
proxy / http://instance1:1234 http://instance2:1234 {
...
health_check /
health_check_port 5678
health_check_contains ''"alive":true'
transparent
}
}
Is there any way to achieve that without writing plugins or extending Caddy? Thanks in advance.