在CentOS下运行的Node.js应用程序的连接超时

我按照这个教程在我的CentOS上创build了一个简单的node.js应用程序:

node.js版本是:

$ node -v v0.10.28 

这是我的app.js

 // Include http module, var http = require("http"), // And url module, which is very helpful in parsing request parameters. url = require("url"); // show message at console console.log('Node.js app is running.'); // Create the server. http.createServer(function (request, response) { request.resume(); // Attach listener on end event. request.on("end", function () { // Parse the request for arguments and store them in _get variable. // This function parses the url from request and returns object representation. var _get = url.parse(request.url, true).query; // Write headers to the response. response.writeHead(200, { 'Content-Type': 'text/plain' }); // Send data and end response. response.end('Here is your data: ' + _get['data']); }); // Listen on the 8080 port. }).listen(8080); 

但是,当我上传这个应用程序到我的远程服务器(假设地址是123.45.67.89),我无法访问它在我的浏览器

http://123.45.67.89:8080/?data=123

浏览器返回Error code: ERR_CONNECTION_TIMED_OUT

我尝试了相同的app.js代码,在我的本地机器上运行良好,有什么我失踪?

我试图ping服务器,其地址是可达的。

谢谢。

我会猜测你没有打开你的防火墙的端口8080.你可以使用iptables命令来做到这一点

 iptables -I INPUT -p tcp -m tcp --dport 8080 -j ACCEPT 

如果这个工作,你可以保存你的防火墙状态

 service iptables save