节点js服务器不能在共享主机服务器上工作

我正在做一个Node.js应用程序。

节点js为我的应用程序托pipe不起作用,所以我只是创build一个小的示例演示托pipe节点js在服务器上,但仍然无法正常工作。

我分享你的代码和步骤,直到现在我已经完成设置代码。

ServerDemo.js

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

然后我从serverdemo.js连接我的服务器,然后使用以下命令运行我的serverdemo.js

 nodejs /var/www/websites/webrtc.windinternet.nl/htdocs/webrtcapp/serverdemo.js 

它会如此输出

 Server running at : http://0.0.0.0:12043/ 

然后我进入

 $ netstat -an | grep "LISTEN " 

这样下面的输出

 tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:12043 0.0.0.0:* LISTEN tcp6 0 0 :::4949 :::* LISTEN tcp6 0 0 :::21 :::* LISTEN tcp6 0 0 ::1:25 :::* LISTEN tcp6 0 0 :::80 :::* LISTEN 

所以端口12043正在监听,但是当我运行$ nmap -sT localhost命令时,它只显示下面的端口是打开的:

 PORT STATE SERVICE 21/tcp open ftp 22/tcp open ssh 25/tcp open smtp 80/tcp open http 3306/tcp open mysql 

当我试图访问http://test.domain.com:12043它总是显示The webpage is not available

如果您需要我的更多描述,请添加评论。

当你按照我的问题在共享服务器上托pipeNode.js应用程序时,必须按照上面提到的步骤运行,最后需要在服务器上打开受尊重的端口来运行node.js应用程序。

命令:telnet -l username test.domain.com 12043

这个telnet命令打开尊重的端口,你的应用程序工作正常。

下面的代码将工作。 尝试一次…

给你的机器一个IP地址或localhost而不是0.0.0.0

 var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(12043, 'localhost'); console.log('Server running at : http://localhost:12043/');