NodeJS server unreachable externally

I deployed the nodejs server in Rackspace and can be accessed internally, for example:

curl http://127.0.0.1:8080

However, it cannot be accessed externally (on the Internet), even if I do this:

iptables -A OUTPUT -p tcp  --dport 8080 -j ACCEPT
iptables -A INPUT -p tcp  --dport 8080 -j ACCEPT

This is what my code looks like:

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Simple server\n');
}).listen(8080, "0.0.0.0");
console.log('Server running at http://0.0.0.0:8080/');

Any ideas?

+6
source share
3 answers

I'm sure you need to use

iptables -A OUTPUT -p tcp  --sport 8080 -j ACCEPT

for outgoing rule (not dport). Also, maybe there is an earlier rule that blocks traffic? Give it a try iptables -L.

+8
source

I think you should try not to specify IP.

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Simple server\n');
}).listen(8080);
console.log('Server running at http://0.0.0.0:8080/');
+9
source

Nodejs . ,

  1. listen (PORT) JS, PORT 8080
  2. :
$ sudo iptables -I INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
0

All Articles