简体   繁体   English

在特定IP地址EADDRNOTAVAIL上的node.js server.listen

[英]node.js server.listen on a specific IP address EADDRNOTAVAIL

When I try to listen on a specific IP address, I am getting an error. 当我尝试监听特定的IP地址时,出现错误。

var http = require('http');

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(8080, "10.211.56.1");

console.log('Server running at http://10.211.56.1:8080/');

I get the following error: 我收到以下错误:

➜  node-test  sudo node server.js
Server running at http://10.211.56.1:8080/
events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: listen EADDRNOTAVAIL
    at exports._errnoException (util.js:746:11)
    at Server._listen2 (net.js:1139:19)
    at listen (net.js:1182:10)
    at net.js:1280:9
    at dns.js:85:18
    at process._tickCallback (node.js:355:11)
    at Function.Module.runMain (module.js:503:11)
    at startup (node.js:129:16)
    at node.js:814:3

This basically means the ip/port combo you are using is not available to your server. 这基本上意味着您使用的ip / port组合不适用于您的服务器。 This could be because the port is already in use, or, that ip address isn't one your server is using. 这可能是因为该端口已在使用中,或者该IP地址不是您的服务器正在使用的IP地址。

You should instead be either using localhost:someport or 0.0.0.0:someport , where someport is a port that isn't currently being used. 您应该改用localhost:someport0.0.0.0:someport ,其中someport是当前未使用的端口。

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

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