Socket io doesnt connect only in cloudflare

I have setup a socket io server and when client makes request it shows that the client connected but in client it throws an error but using localhost or https://ip:port it works.
I have enabled Websockets in network tab, I have valid ssl certificates both on Cloudflare and server.

My website url: https://conspirey.xyz and you can test it

Your backend server (the one running the socket.io server) is returning a 403 - unauthorized
It looks like this may be because Socket.io has an “origin” setting where you specify the origins which are allowed to use your websocket server.
I found these posts on topic:
javascript - Have issues with socket io on backend connecting with my quasar app. Code 403(Forbidden) error with Socket io - Stack Overflow
websocket - Socket IO forbidden 403 - Stack Overflow
Either way, it seems the problem is with your origin web server, and not Cloudflare. It only shows on Cloudflare because your websocket server sees your website as an unauthorized origin.

Hello! I tested the socket Io again but it doesn’t seem to return any status, but I have setup https://conspirey.xyz/ws that connects with plain websocket, i have fixed any origin errors but still it doesn’t connect to websockets

I have tested the site in https://vm5.spacerv.ovh:3623 and everything works, but doesnt in Cloudflare.

The problem I see now is the port. Your website behind Cloudflare is trying to connect to a web socket on wss://conspirey.xyz:3623/echo.

That is not one of Cloudflare’s supported ports:

Even forcing it to normal https/443 doesn’t work, so I’m guessing you’re running the socket.io server on a separate port? (Not familiar with socket.io)
You could put it behind a reverse proxy like nginx, looks like they have guides for that: https://socket.io/docs/v4/reverse-proxy/
You could also try making an origin rule rewrite the destination port based on the path.

Edit: Looking at again, the working example you gave is on the same port. I wonder if it’s something as simple as fixing the port issue, and making sure you have Websockets enabled within Cloudflare (Network → Websockets).

Hello! Yes, I have enabled websockets in the network tab.

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