8

I deployed a nodejs server in Rackspace and can be accessed internally, like using:

curl http://127.0.0.1:8080

However, it can't be accessed from the outside (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

Here 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?

thejh
  • 44,854
  • 16
  • 96
  • 107
quarks
  • 33,478
  • 73
  • 290
  • 513

3 Answers3

9

I think you should try not specifying an 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/');
Farid Nouri Neshat
  • 29,438
  • 6
  • 74
  • 115
  • tried it just now, but still don't work. Is this what you do in your server. How do you setup iptables for your nodejs server? – quarks Nov 05 '11 at 07:08
8

I am pretty sure that you have to use

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

for the outgoing rule (not dport). Apart from that, maybe there's an earlier rule that blocks the traffic? Try iptables -L.

thejh
  • 44,854
  • 16
  • 96
  • 107
3

Faced same issue while configuring Nodejs on local virtual machine. Try below steps,

  1. Use listen(PORT) in JS code, in your case PORT will be 8080
  2. Add below entry in server machine:
$ sudo iptables -I INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
Alpesh Patil
  • 1,672
  • 12
  • 15