A
A
Albert Ushakov2020-07-12 07:53:29
Node.js
Albert Ushakov, 2020-07-12 07:53:29

How to run node js server on VDS with external access from browser?

Trying to run a Node server on a VDS and ran into a port issue.
Hosting does not have explicit access, for example, on port: 3000, and it turns out there is no external access, such as site.ru
: 3000 And this is where the problem with the socket arises. Where to send requests so that the server can process it?

Most likely you need to start the server on port 80, and open the page through the node itself with port forwarding.

How to implement this without breaking all the sites on this server? Since there are several sites on one IP. (Yes, there is an option to buy another IP).

The node server code:

var http = require('http');
var server = http.createServer((req, res) => {
    res.statusCode = 200;
    res.setHeader('Content-Type', 'text/plain');
    res.end('Hello World\n');
});
var fs = require('fs');
var mysql = require('mysql');
var port = 3000;
var site = "127.0.0.1";

var io = require('socket.io').listen(server);
server.listen(port, site, (err) => {
    if (err) {
        return console.log('Ошибка сервера: ', err)
    }
    console.log("Статус сервера: OK");
})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Gavrilov, 2020-07-12
@thexaver

Proxy with nginx

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question