![](/img/trans.png)
[英]Can't reach localhost:PORT created in Node.js and express
[英]Node.js can access default port, but can't access specific port
http.createServer(function(request, response){
response.writeHead(404, {'Content-Type': 'text/plain'});
response.write('Helloworld!');
response.end();
}).listen(3000,function(){
console.log("server listen on port::: 3000");
});
上面是在Ubuntu中运行的一个非常简单的代码段。 我可以通过默认端口(80)正常访问,但不能通过特定端口访问。 我访问的是外部IP,而不是内部localhost。 我可以通过“ curl xxxx:3000”命令行获得正确的响应,但是我无法在Web浏览器中将其打开。 任何可以提供提示的人都会感激!!!
一个进程可能正在使用该端口。
netstat -tulpn | grep 3000
netstat -tulpn | grep 3000
将为您提供使用端口的进程。
如果找不到,请检查您的iptables。
编辑:根据评论的建议,可能是OP台式机限制了对非HTTP端口的外部请求。 简单的iptable即可。
-A OUTPUT -d **dest_ip**/32 -p tcp -m tcp --dport 3000 -j ACCEPT
用您的IP替换dest_ip 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.