Node.JS不在互联网上工作

时间:2022-03-06 00:12:32

i have the basic webserver hello world app for nodejs on windows and it works on localhost. But when i test it from the internet it cannot connect. I set up port forwarding in my netgear router. Am i missing a step here to make my nodejs server visible to the outside world?

我在windows上有nodejs的基本webserver hello world app,它可以在localhost上运行。但是,当我从互联网上测试时,它无法连接。我在我的netgear路由器中设置了端口转发。我错过了一步让我的nodejs服务器对外界可见吗?

Thanks.

谢谢。

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 running at http://127.0.0.1:1337/');

2 个解决方案

#1


17  

Make sure you listen on 0.0.0.0 instead of 127.0.0.1

确保您收听0.0.0.0而不是127.0.0.1

127.0.0.1 is a private network visible only to your computer. 0.0.0.0listens to all interfaces, including both the private and public (as public as it can be behind a NAT).

127.0.0.1是仅对您的计算机可见的专用网络。 0.0.0.0可以访问所有接口,包括私有接口和公共接口(与NAT后面的公共接口一样)。

#2


0  

Looks like you're binding the server to IP Address 127.0.0.1 which is localhost. If you want to access it elsewhere you'll need to set it to it's internet IP. Check out whatismyip.com and use that IP instead.

看起来您正在将服务器绑定到IP地址127.0.0.1(localhost)。如果你想在别处访问它,你需要将它设置为它的互联网IP。查看whatismyip.com并使用该IP。

#1


17  

Make sure you listen on 0.0.0.0 instead of 127.0.0.1

确保您收听0.0.0.0而不是127.0.0.1

127.0.0.1 is a private network visible only to your computer. 0.0.0.0listens to all interfaces, including both the private and public (as public as it can be behind a NAT).

127.0.0.1是仅对您的计算机可见的专用网络。 0.0.0.0可以访问所有接口,包括私有接口和公共接口(与NAT后面的公共接口一样)。

#2


0  

Looks like you're binding the server to IP Address 127.0.0.1 which is localhost. If you want to access it elsewhere you'll need to set it to it's internet IP. Check out whatismyip.com and use that IP instead.

看起来您正在将服务器绑定到IP地址127.0.0.1(localhost)。如果你想在别处访问它,你需要将它设置为它的互联网IP。查看whatismyip.com并使用该IP。