0

I have a cpanel where Apache is activated and displaying my website on port 80,443 https://mydomain.io

The below setup works on port 80 but not on other ports like if I want to run this at Port 8070

I want to run nodejs on port 8070 i.e http://IP:8070

SERVER SIDE

server.js

var compression = require('compression'); var _ = require('lodash'); var express = require('express'); var server = express(); var app = require('http').createServer(server); var io = module.exports.io = require('socket.io')(app); server.use(compression()); app.get('/', (req, res) => { res.sendFile(__dirname + '/tester.html'); }); app.listen(8070, function(){ console.log('listening on *:' + 8070); }); 

Now when I open this IP:8070 this renders the HTML and it connects to sockets

WORKING

console.log(io.connect());

But I want to access it via mydomain.io

so If I try to go to mydomain.io/tester.html or a file locally on my pc

It doesn't connect to sockets

//NONE OF THESE WORKING!

WITH HTTP GETTING ERR:

 console.log(io.connect('http://mydomain.io:8070/', { transports: ["websocket"]})); console.log(io.connect('http://localhost:8070/', { transports: ["websocket"]})); console.log(io.connect('http://localhost/', { transports: ["websocket"]})); console.log(io.connect('http://mydomain.io/', { transports: ["websocket"]})); console.log(io.connect()); GETTIG ERR: Mixed Content: The page at '<URL>' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws:<URL>/socket.io/?EIO=3&transport=websocket'. This request has been blocked; this endpoint must be available over WSS. 

WITH HTTPS NOT WORKING

 console.log(io.connect('https://mydomain.io:8070/', { transports: ["websocket"]})); console.log(io.connect('https://localhost:8070/', { transports: ["websocket"]})); console.log(io.connect('https://localhost/', { transports: ["websocket"]})); console.log(io.connect('https://mydomain.io/', { transports: ["websocket"]})); 

WITH PORT 80 ITS WORKING BUT NOT ON ELSE

BUT if I run my server.js at port 80 and stopping apache using service httpd stop

then it works with mydomain.io/tester.html or a file locally on my pc

var socket = io.connect('wss://mydomain.io'); //Socket Address WOKRING 

enter image description here

3
  • Can you add your apache config here as well, are you using apache to setup a reverse proxy to your nodejs server? Commented Mar 14, 2021 at 6:42
  • No I don't want a reverse proxy I want node to run seperate and fetch using sockets Commented Mar 14, 2021 at 8:03
  • 2
    I think this can be fixed if you setup a secure websocket, ref: stackoverflow.com/questions/31338927/… Commented Mar 14, 2021 at 12:14

1 Answer 1

0

Yes, Thank you @v1shva, trying https.createserver instead of http createserver with my cpanel keys and cert file I am able to connect with this from anywhere.

Thank You

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.