[英]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.