简体   繁体   English

Node.js可以访问默认端口,但不能访问特定端口

[英]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");
});

Here above is a quite simple snippet run in Ubuntu . 上面是在Ubuntu中运行的一个非常简单的代码段。 I can access normally by default port(80), but can't access by a specific port. 我可以通过默认端口(80)正常访问,但不能通过特定端口访问。 What I accessed is an external IP, not internal localhost. 我访问的是外部IP,而不是内部localhost。 I can get correct response via command line of "curl xxxx:3000", but I just can't open it in web browsers. 我可以通过“ curl xxxx:3000”命令行获得正确的响应,但是我无法在Web浏览器中将其打开。 Anybody who can give a hint will be appreciated!!! 任何可以提供提示的人都会感激!!!

A process is probably using the port. 一个进程可能正在使用该端口。

netstat -tulpn | grep 3000 netstat -tulpn | grep 3000 will give you what process is using the port. netstat -tulpn | grep 3000将为您提供使用端口的进程。

If none found, look into your iptables. 如果找不到,请检查您的iptables。

Edit: As suggest from comment, probably OP desk that restrict external request for non http ports. 编辑:根据评论的建议,可能是OP台式机限制了对非HTTP端口的外部请求。 Simple iptable will do. 简单的iptable即可。

-A OUTPUT -d **dest_ip**/32 -p tcp -m tcp --dport 3000 -j ACCEPT

Replace dest_ip by your ip. 用您的IP替换dest_ip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM