node.js - linode新手问题,关于node直接监听端口,外网通过ip访问不了的问题?
ringa_lee
ringa_lee 2017-04-17 11:15:13
0
1
732

情况如此:
在linode已经安装好了node,并且写了个demo(node官网那段hello,world),在服务器上运行无问题,curl localhost也可以返回。但是如果 curl ip 就访问不了。当然外网不能访问。
我已经查看了80端口。已经被node占用。
查看防火墙,也开启了web访问。(或者就说没开。。)
没找到原因。

后来装了nginx,start nginx后没问题,都可以访问。

想问下原因?之前在阿里云上直接运行node都可以。。

ringa_lee
ringa_lee

ringa_lee

reply all(1)
伊谢尔伦
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/');

This is the Demo from the official website. It has been written above that only the local loopback address is monitored. If you omit the second parameter of listen, you can listen to all addresses.

PS: Another troubleshooting tip:

Using netstat -lnp you can also see whether a program is monitoring 127.0.0.1 or 0.0.0.0.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template