节点JS不听服务器端口1337

我试图在Google托pipe的特定灯服务器上打开端口,并通过ssh与服务器连接。

我已经按照这个链接来configurationnvm和最新的Node JS(v0.12.5)。 安装之后,我在“server.js”文件中使用了这个演示代码,并使用命令“node server.js”,它看起来像Node JS正在运行,在服务器控制台给出这个消息“Server ready”。 现在问题是,当我使用“netstat -n”检查打开的端口时,我没有看到任何1337端口打开,它应该是。 我也尝试使用“serverIPaddress:1337”通过浏览器进行连接,但是我收到“Conecting …”消息,然后没有任何反应。

任何想法,我搞乱了? 我也混淆了服务器IP地址(本地主机:127.0.0.1)或(globalIPaddress)放在server.js文件。

PS:请在下面findserver.js文件脚本。

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

你有两个问题:

1)“127,0,0,1”表示“本地主机” – 如果你想要远程客户端连接,这是不合适的。

2)端口1337可能(或可能不)通过防火墙开放。 这听起来好像不是。

build议更改:

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

假设您的远程服务器没有一些已经绑定到端口80的其他Web服务器。如果您的修改后的程序因“端口正在使用”错误而死机,请尝试使用端口8080或端口8888。

尝试删除“127.0.0.1”或更改为0.0.0.0 – 以侦听所有接口。 有关详细信息,请参阅文档https://nodejs.org/api/http.html#http_server_listen_port_hostname_backlog_callback

使用当前设置,服务器只接受来自本地主机的连接。 你也需要调整防火墙来打开远程服务器上的1337端口

只要把端口号码,而不是使用端口号码和IP地址

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

如果你想使用IP地址比服务器将只能从本地访问URL 127.0.0.1:1337您将无法访问它与localhost:1337