We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Configuring the Load Balancer

We've confirmed that we have 2 application servers (Caddy) working properly on a custom bridge network. Let's create a load balancer that balances network requests between the two! We'll use a round-robin balancing strategy, so each request should route back and forth between the servers.

Caddyfiles

Caddy works great as a file server, which is what our little HTML servers are, but it also works great as a load balancer! To use Caddy as a load balancer we'll need to create a custom Caddyfile to tell Caddy how we want it to balance the traffic. It's just a config file for Caddy.

Assignment

localhost:80

reverse_proxy caddy1:80 caddy2:80 {
	lb_policy       round_robin
}

This tells Caddy to run on localhost:80, and to round robin any incoming traffic to caddy1:80 and caddy2:80. Remember, this only works because we're going to run the loadbalancer on the same network, so caddy1 and caddy2 will automatically resolve to our application server's containers.

docker run -d --network caddytest -p 8880:80 -v $PWD/Caddyfile:/etc/caddy/Caddyfile caddy

If it's not swapping properly, try using curl instead. Your browser might be caching the HTML.

curl http://localhost:8880/

Run and submit the CLI tests.