2011-11-05 73 views
5

访问我在Rackspace公司部署了服务器的NodeJS和可以在内部进行访问,就像使用:服务器的NodeJS不从外部

curl http://127.0.0.1:8080

但是,不能从外部(互联网)访问,甚至如果我这样做:

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

这里是我的代码如下所示:

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/'); 

任何想法?

回答

6

我敢肯定,你必须使用

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

的传出规则(不dport)。除此之外,也许有更早的规则阻止流量?尝试iptables -L

+0

很酷。谢啦。它现在有效 – xybrek

7

我认为你应该尝试不指定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/'); 
+0

刚才试过了,但还是不行。这是你在你的服务器中做什么。你如何为你的nodejs服务器设置iptables? – xybrek

+1

执行iptables行后,这对我有用。 –

+0

这一步之后的答案也适用于我。 –