0

I am running my nodejs server with port 8443 on localhost.

i.e. http://localhost:8443 or https://localhost:8443

Now, I have deployed the project on one server instance with IP say xxx.xxx.xxx.xxx

I have started the node server on it for the same port.

From this server instance, I can access the node server locally as I can do for my localhost machine.

But How can I access the node server publicly from outside of server at 8443?

i.e. xxx.xxx.xxx.xxx:8443

num8er
  • 18,604
  • 3
  • 43
  • 57
RIYAJ KHAN
  • 15,032
  • 5
  • 31
  • 53
  • 1
    listen(8443, '0.0.0.0'); or without 0.0.0.0: listen(8443); – num8er Nov 23 '16 at 18:23
  • 1
    And make sure that your firewall accepts inbound TCP connections on port 8443 – doublesharp Nov 23 '16 at 18:27
  • [Redirect port 80](http://stackoverflow.com/questions/16573668/best-practices-when-running-node-js-with-port-80-ubuntu-linode) – mattdevio Nov 23 '16 at 18:27
  • @magreenberg RIYAJ does not want to redirect 80th to 8080 and 443 to 8443. He is trying to access app globally at defined port. also it's better to set app behind normal webserver (for example: nginx, apache), cuz every app has it's static files, that's not recommended to handle on nodejs app. – num8er Nov 23 '16 at 18:34

1 Answers1

0

checkout this simple example:

var
  fs = require('fs'),
  express = require('express'),
  app = express(),
  http = require('http'),
  https = require('https');

app.get('/', function(req, res) {
  res.send('Hello World!');
});

var httpServer = http.createServer(app);
httpServer.listen(8080, '0.0.0.0', function () {
  console.log('App listening at http://0.0.0.0:8080');
});

var httpsConfig = {
  key: fs.readFileSync('path/to/certificate.key'),
  cert: fs.readFileSync('path/to/certificate.crt')
};
var httpsServer = https.createServer(httpsConfig, app);
httpsServer.listen(8443, '0.0.0.0', function () {
  console.log('App listening at https://0.0.0.0:8443');
});
num8er
  • 18,604
  • 3
  • 43
  • 57
  • So,is it virtual hoasting for nodejs? – RIYAJ KHAN Nov 27 '16 at 08:36
  • @RIYAJKHAN It's an example code to run expressjs app on 8443 port that listens on all network interfaces (devices) of server. If it's cheap php hosting service so of course it will not run (: more info about hosting will be usefull – num8er Nov 27 '16 at 12:07