节点JS没有监听服务器上的端口1337 [英] Node JS not listening to port 1337 on server

查看:229
本文介绍了节点JS没有监听服务器上的端口1337的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Google托管的特定灯服务器上打开一个端口,我通过ssh与服务器连接。

I'm trying to open a port on particular lamp server hosted by Google and I'm in connection with the server via ssh.

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

I've followed this link to configure nvm and the latest Node JS(v0.12.5) on it. After installing, I've used this demo code in "server.js" file and using the command "node server.js", it looks like Node JS is running, giving this message "Server ready" at the server console. Now the problem is that when I check for the open port using "netstat -n", I dont see any 1337 port open, which it should be. I've also tried to connect through browser using "serverIPaddress:1337", but I get "Conecting..." message and then nothing happens.

任何想法我搞砸了?
我还要将服务器IP地址(localhost:127.0.0.1)或(globalIPaddress)与server.js文件放在一起。

Any idea where I'm messing up?? I'm also confused with the server IP address(localhost:127.0.0.1) or (globalIPaddress) to put in the server.js file.

P.S:请在下面找到server.js文件脚本。

P.S: Please find the server.js file script below.

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表示localhost - 如果您希望远程客户端连接,则不合适。

1) "127,0,0,1" means "localhost" - it is NOT appropriate if you want remote clients to connect.

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

2) port 1337 may (or may not) be open through a firewall. It sounds like it isn't.

建议更改:

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');

这假设您的远程服务器没有某个OTHER Web服务器已绑定到端口80。如果您修改的程序因正在使用的端口错误而死亡,请尝试端口8080.或端口8888.

This is assuming that your remote server doesn't have some OTHER web server already bound to port 80. If your revised program dies with a "port in use" error, then try port 8080. Or port 8888.

这篇关于节点JS没有监听服务器上的端口1337的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆