2011-11-05 56 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

這一步之後的答案也適用於我。 –