caddy icon indicating copy to clipboard operation
caddy copied to clipboard

Websocket issues from 2.9*

Open mooseh opened this issue 2 months ago • 4 comments

Issue Details

so recently i needed to create a new docker build for my work which i have used before, however because i was using latest tag in the builder the version of caddy was much greater than the last time i built it, and this has highlighted some issues with websockets, i then worked back with the builder numbers until i got to 2.8 where everything is working again.

basically when reverse_proxying a websocket it closes the connection without any valid reason.

here is the dockerfile

FROM caddy:2.8-builder-alpine AS builder

RUN xcaddy build \
    --with github.com/caddy-dns/cloudflare@188b4850c0f2f5565a6310810c936ea960e2210f \
    --with github.com/caddy-dns/[email protected]

FROM caddy:alpine

COPY --from=builder /usr/bin/caddy /usr/bin/caddy

here is the Caddyfile (anonymized)

*.mydomain.com *.dev.mydomain.com {

	#PORTAL
	@portal_http {
		host portal.dev.mydomain.com
	}

	@portal_ws {
		host portal.dev.mydomain.com
    	header Connection *Upgrade*
    	header Upgrade websocket
	}

	handle @portal_ws {
		header {
			Identifier "soketi"
		}
		reverse_proxy portal_soketi:6001 {
			header_up Connection {http.request.header.Connection}
			header_up Upgrade {http.request.header.Upgrade}
		}
	}

	reverse_proxy @portal_http portal_web {
			header_up Host {host}
			header_up X-Real-IP {remote}
			header_up X-Forwarded-Port 443

			health_timeout 5s
	}

	tls {
		dns route53
	}
	
}

Assistance Disclosure

No response

If AI was used, describe the extent to which it was used.

websockets not working from builder version 2.9 upwards.

mooseh avatar Oct 31 '25 08:10 mooseh

What are the relevant logs for those websocket requests? How are these requests logged if caddy 2.8 is used?

WeidiDeng avatar Oct 31 '25 11:10 WeidiDeng

Remove all your header_up lines, none of them do anything useful. Caddy already passes through the relevant HTTP headers, including X-Forwarded-For.

francislavoie avatar Oct 31 '25 13:10 francislavoie

I had the same problem, too - #7292 appears to have fixed the issue.

mgoeppl avatar Nov 02 '25 21:11 mgoeppl

#7292 fixed issue where tls server name contains placeholders and is for version 2.10.1, which doesn't apply in this issue.

WeidiDeng avatar Nov 03 '25 04:11 WeidiDeng