Wss

Relayd with WSS

Some apps, mostly like multiplayer games, are running on a port and need an websocket.

Most of the time you would want to put it on a subdomain, but then the websocket should still go on a port, but the software doesn't allow it, since it polls using http first and then connects to websocket and they just cannot be seperate ports.

This is why you should add these things to your relayd.conf

Instructions

We assume your relayd.conf looks like this:

http protocol https {
        match request header append "X-Forwarded-For" value "$REMOTE_ADDR"
        match request header append "X-Forwarded-By" \
            value "$SERVER_ADDR:$SERVER_PORT"
        match request header set "Connection" value "close"
        tcp { sack, backlog 128 }
        tls { keypair service1.example.com }
        tls { keypair service2.example.com }
        match request header "Host" value "service1.example.com" forward to <service1>
        match request header "Host" value "service2.example.com" forward to <service2>
}

P.s. this is the config from Relayd.Acceleration

Now, in order to add support for websockets, just add these lines before the tcp { sack, backlog 128 } line

        match request header "Upgrade" value "websocket" header set "Connection" value "upgrade"
        http websockets

This would result into:

http protocol https {
        match request header append "X-Forwarded-For" value "$REMOTE_ADDR"
        match request header append "X-Forwarded-By" \
            value "$SERVER_ADDR:$SERVER_PORT"
        match request header set "Connection" value "close"
        match request header "Upgrade" value "websocket" header set "Connection" value "upgrade"
        http websockets
        tcp { sack, backlog 128 }
        tls { keypair service1.example.com }
        tls { keypair service2.example.com }
        match request header "Host" value "service1.example.com" forward to <service1>
        match request header "Host" value "service2.example.com" forward to <service2>
}

Now reload your relayd using doas rcctl reload relayd and you should be good to go!