NodeJS server and client on Cpanel Not Working

20 Views Asked by At

I have made a functional nodejs application that acts as a websocket server and serves a simple client webpage. I have the websocket at port 8080, and the client connects too from wss://192.168.3.101:8080. This works locally. But when I transfer this over to a Cpanel nodejs webapp on my personal domain it doesn't connect.

I understand that 192.168.3.101:8080 is only on my ip address. What address should I try connecting the client script to?

1

There are 1 best solutions below

0
Safwan Parkar On

I seriously doubt you need a WebSocket server to serve a client webpage. But I don't know all the details, so here's a generic solution.

Ideally, you would use a global configuration (most common and simplest way is to use an environment variable) to set the hostname of your application.

On your local network, the hostname is 192.168.3.101, but on cPanel it will be a different public IP, or ideally a domain. I recommend using a domain since IP addresses tend to change when the "machine" is rebooted.

What I would do, is setup a reverse proxy with nginx and configure a virtual host to serve WebSocket requests. The following link is a good resource that will explain step by step what to do: https://www.nginx.com/blog/websocket-nginx/