Caddy v2 wesocket load balance

1. The problem I’m having:

Hello. Can I use load balance policy for websocket reverse proxy? Can’t find any docs.

2. Error messages and/or full log output:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

3. Caddy version:

v2.6.4

4. How I installed and ran Caddy:

a. System environment:

docker run caddy:v2.6.4

b. Command:

caddy run --config /etc/caddy/Caddyfile

c. Service/unit/compose file:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

d. My complete Caddy config:


reverse_proxy 1.1.1.1:82 1.1.1.2:82 {
	header_regexp Connection *Upgrade*
	header        Upgrade websocket
}

5. Links to relevant resources:

These are invalid config inside reverse_proxy.

Caddy’s reverse_proxy supports proxying WebSocket connections out of the box, there’s nothing extra to do.

This will automatically load balance across the two backends, using the default lb_policy of random. See the docs: reverse_proxy (Caddyfile directive) — Caddy Documentation

Setting up load balancing involves a lot of questions to get it right. You probably want to also enable retries, and active/passive health checking so that Caddy can figure out which upstreams are unhealthy.

This is configuration is valid for ws? I get config from Websockets over https

reverse_proxy 1.1.1.1:82 1.1.1.2:82 {
  header Connection *Upgrade*
  header Upgrade websocket
}

No, that’s wrong.

All you need is this, to start:

reverse_proxy 1.1.1.1:82 1.1.1.2:82

You don’t need to do anything with headers for WebSockets. It’s completely automatic.

But like I said, you do need to configure more things for load balancing. See the docs.

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