开发者社区> 问答> 正文

ECS部署nodejs服务器失败,“无法分配IP地址”

我购买了ecs主机想要部署nodejs服务器,选择的系统为centos,网络为专用网络

尝试ECS部署nodejs服务器失败,“无法分配IP地址”
const http = require('http');
const hostname = '47.93.220.230';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
server.listen(port, hostname, function(){
console.log(`Server running at http://${hostname}:${port}/`);
});



hostname为我的ecs实例公网ip地址,执行node index.js命令后显示:

listen EADDRNOTAVALL  hostname:port

小白求助


展开
收起
nxzhengli 2017-05-14 13:29:18 3783 0
2 条回答
写回答
取消 提交回答
  • 旺旺:nectar2。
    楼主您好,

    抱歉给您带来不便,

    如果您使用的是Linux系统,请先运行 ifconfig 的命令,查看公网IP 47.93.220.230 是否在本地系统中,

    一般专有网络中的ECS实例,公网IP的配置是在系统之外的,所以不能在程序中,如您的 nodejs 里直接配置公网IP的监听喔,建议是使用 0.0.0.0,

    const hostname = '0.0.0.0';
    2017-05-14 14:38:59
    赞同 展开评论 打赏
  • ReECS部署nodejs服务器失败,“无法分配IP地址”
    作为服务方,不需要绑定具体IP地址,只需绑定端口即可。
    2017-05-14 14:09:00
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
如何运维千台以上游戏云服务器 立即下载
网站/服务器取证 实践与挑战 立即下载
ECS快储存加密技术 立即下载