2015-12-29 53 views
2

我正在研究Node.js应用程序。节点js服务器无法在共享托管服务器上工作

主机节点JS的我的​​应用程序不能正常工作,所以我只需要创建一个小样本演示托管在服务器节点的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使用下面的命令

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

如果你需要从我身边的任何更多的描述,请添加注释。

+0

您是否检查是否有防火墙规则阻止端口?运行'iptables -nvL'来查看所有规则,在这种情况下'OUTPUT'和'INPUT'链的规则很有趣。 – cdauth

+0

此外,您可能尝试使用telnet从您的计算机打开连接:'telnet test.domain.com 12043'。 – cdauth

+0

我会冒险猜测'nmap -sT'默认情况下不会检查端口12043,除非您明确指示它这样做。 – robertklep

回答

0

虽然你的主机共享服务器上的Node.js应用程式按我的问题,你必须运行按照上面的步骤,我提到,最后,你需要打开尊敬的端口服务器上运行的node.js应用。

命令:telnet -l用户名test.domain.com 12043

此telnet命令打开尊重端口,您的应用程序工作正常。下面

0

的代码将工作。尝试一次...

给你的机器一个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/'); 
相关问题