How to set up a Secure WebSocket server on NodeJS with CloudFlare SSL?

Hello!
How to set up a Secure WebSocket server (wss://) on NodeJS with CloudFlare SSL?
I tried to

  • Use self-generated key.pem and cert.pem in https.createServer
  • Use privkey.pem and cert.pem (generated with certbot) in https.createServer
  • Do not use any key.pem and cert.pem
    Still does not work, my browser shows the net::ERR_SSL_PROTOCOL_ERROR error.

I am afraid that is rather a question for StackOverflow.

You should not use a self-signed certificate however, as that wouldn’t be secure in either context. Use Lets Encrypt instead. What you need to do is get that service up and running without Cloudflare and once it works, you can add Cloudflare to it.

How to use Lets Encrypt here?
Where to get these key.pem and cert.pem files?

You could also get a Cloudflare Origin certificate instead, but that could be an issue during testing without Cloudflare as the connection would be still untrusted.

I want wss to work here and anti-ddos to work on it. what is the fastest and easiest thing I can do?

Set up a certificate, make sure it works well without Cloudflare, then add Cloudflare.

This error disappeared when I changed DNS mode from “proxied” to “dns only”. Does this disable cloudflare’s anti-ddos protection? If yes, then how to deal with this? If no, then what does this switcher change??

So it works when not proxied?

Post a screenshot of the error and what is the actual URL?

websocket server address:
wss://ws.wynell.website:8080
error:

Port 8080 is HTTP only, you need to use an SSL enabled port

2 Likes

:thinking: :thinking: :thinking: Ok, I am going to try this.

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