简体   繁体   中英

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 . I can access normally by default port(80), but can't access by a specific port. What I accessed is an external IP, not internal localhost. I can get correct response via command line of "curl xxxx:3000", but I just can't open it in web browsers. 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.

If none found, look into your iptables.

Edit: As suggest from comment, probably OP desk that restrict external request for non http ports. Simple iptable will do.

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

Replace dest_ip by your ip.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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