This setup checks each backend’s health by sending requests to /health every 10 seconds. If a backend doesn't respond within 2 seconds, it's considered unhealthy. Load balancing is done using the round_robin strategy.
This configuration uses a failover strategy, where Caddy tries the first backend, and if it fails, it switches to the next backend, retrying every 5 seconds for up to 30 seconds.
These configurations can be adjusted depending on the needs of your infrastructure.
Here are some examples of load balancing configurations for Caddy:
1. Basic Load Balancing Across Multiple Backends
This configuration will load balance requests to
/api/*
acrossbackend1
,backend2
, andbackend3
on port 8080.2. Load Balancing with Health Checks
This setup checks each backend’s health by sending requests to
/health
every 10 seconds. If a backend doesn't respond within 2 seconds, it's considered unhealthy. Load balancing is done using theround_robin
strategy.3. Sticky Sessions with Load Balancing
Here, sticky sessions are enabled using cookies. Clients will be consistently routed to the same backend based on
my_sticky_cookie
.4. Load Balancing with Failover
This configuration uses a failover strategy, where Caddy tries the first backend, and if it fails, it switches to the next backend, retrying every 5 seconds for up to 30 seconds.
These configurations can be adjusted depending on the needs of your infrastructure.