Receiving response from simple load balancer inside a Docker container

1. Output of caddy version:

v2.6.1 h1:EDqo59TyYWhXQnfde93Mmv4FJfYe00dO60zMiEt+pzo=

2. How I run Caddy:

Within a Docker container

a. System environment:

Unix (AWS Linux 2 AMI)

b. Command:

See below for Docker run command

c. Service/unit/compose file:

docker run \
    --log-driver=fluentd \
    --log-opt tag="cl.caddy" \
    --log-opt fluentd-address=localhost:24224 \
    --restart unless-stopped \
    -u ${DOCKER_USER_ID}:${DOCKER_GROUP_ID} \
    --name caddy \
    -p 8545:8545 \
    -p 8546:8546 \
    -p 50000:50000 \
    -p 50001:50001 \
    -v /lw/caddy:/caddy \
    -v /lw/caddy/Caddyfile:/etc/caddy/Caddyfile \
    -v /lw/caddy:/config/caddy/ \
    -v /lw/caddy:/data \
    -d caddy:2.6.1

d. My complete Caddy config:

http://rpc-internal:50000 {
	respond "internal worked!"
}

http://rpc-external:50001 {
	respond "external worked!"
}

http://rpc-balancer:8546 {
	reverse_proxy {
		to http://rpc-internal:50000 http://rpc-external:50001

		lb_policy first
		lb_try_duration 5s
		lb_try_interval 50ms
	}
}

3. The problem I’m having:

I’m trying to run a basic load balancer within Caddy that can proxy to two endpoints (rpc-internal, rpc-external).

“rpc-internal” will eventually be a local docker container, and “rpc-external” will be an external URL on the public internet, but I can’t even get this basic test case of returning a simple string (ie, “external worked!”) correct.

4. Error messages and/or full log output:


"wget localhost:50000" returns HTTP 200, empty response (expecting "internal worked!").

"wget localhost:50001" returns HTTP 200, empty response (expecting "external worked!").

"wget localhost:8546" returns HTTP 200, empty response (expecting "internal worked!" or "external worked!").

5. What I already tried:

See above for the wget commands that I’ve tried. Thank you!!!

6. Links to relevant resources:

Hi :slight_smile:

hostnames/domains are an exact match, so essentially what’s happening is the following:

  • Your wget localhost:50000 sends a http request with Host: localhost:50000
  • Caddy checks if it is configured to serve anything on localhost:50000 but it only sees rpc-internal:50000
  • So Caddy couldn’t find a match and responds with the default, a blank http/200

You can see that in action when running wget --header "Host: rpc-internal:50000" localhost:50000 instead.

If you plan to use only a single vhost per port anyway, you could use http://:50000 instead of http://rpc-internal:50000

http://:50000 {
	respond "internal worked!"
}

That’s basically a wildcard match for everything on that port :innocent:

2 Likes

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