Unrecognized subdirective websocket

1. My Caddy version (caddy -version):

v2.0.0-beta9

2. How I run Caddy:

nohup ./caddy &
exit

a. System environment:

Ubuntu 18.04

d. My complete Caddyfile:

tunnel.mysite.com {
	reverse_proxy * localhost:8080 {
            websocket
            header_up Host {http.request.host}
            header_up X-Real-IP {http.request.remote}
            header_up X-Forwarded-For {http.request.remote}
            header_up X-Forwarded-Port {http.request.port}
            header_up X-Forwarded-Proto {http.request.scheme}
	}
}

3. The problem I’m having:

When I try to start caddy I see “unrecognized subdirective websocket”

For reference, I am implementing caddy per this post https://blog.alexellis.io/https-inlets-local-endpoints/ and converting from Caddy 1.x to 2.x

Thank you

Hi @petebytes, welcome to the Caddy community!

Caddy v2’s reverse proxy doesn’t have a websocket subdirective.

In Caddy v1, the websocket preset configures two upstream headers, Connection and Upgrade.

You will need to specify these headers manually using request header placeholders (i.e. {http.request.header.FIELD-NAME}) and the header_up subdirective for v2’s reverse_proxy.

https://caddyserver.com/v1/docs/proxy#presets
https://github.com/caddyserver/caddy/wiki/v2:-Documentation#reverse_proxy
https://github.com/caddyserver/caddy/wiki/v2:-Documentation#http-placeholders

Thanks for the quick reply! Here is what I ended up with.

tunnel.mysite.com {
        reverse_proxy * localhost:8080 {
                header_up Host {http.request.host}
                header_up X-Real-IP {http.request.remote}
                header_up X-Forwarded-For {http.request.remote}
                header_up X-Forwarded-Port {http.request.port}
                header_up X-Forwarded-Proto {http.request.scheme}
                header_up Connection {http.request.header.Connection}
                header_up Upgrade {http.request.header.Upgrade}
        }
}
1 Like

Websockets should work with v2’s reverse proxy by default. @petebytes If you remove these lines:

header_up Connection {http.request.header.Connection}
header_up Upgrade {http.request.header.Upgrade}

Does it still work for you?

It does! Thanks :slight_smile:

1 Like

Great!

To clarify, in v2, you do not need to do anything to enable websockets.

1 Like