简体   繁体   English

如何在Ubuntu中设置Node.js应用服务器

[英]How to set up a nodejs application server in ubuntu

I don't understand why i have this problem which i show the output in the second part. 我不明白为什么会有这个问题,我将在第二部分中显示输出。 While following the tutorial "how To Set Up a Node.js Application for Production on Ubuntu 14.04" i did everything. 在遵循教程“如何在Ubuntu 14.04上为生产设置Node.js应用程序”时,我做了所有事情。

I created a script to test my private ip address like this 我创建了一个脚本来测试我的私有IP地址,如下所示

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(8080, 'myPrivateIp');
console.log('Server running at http://myPrivateIp:8080/');

The problem that i encountered while testing the apllication. 我在测试附件时遇到的问题。

JoeDoe@myUbuntu:~$ node hello.js
Server running at http://myPrivateIp:8080/
events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRNOTAVAIL myPrivateIp:8080
    at Object.exports._errnoException (util.js:837:11)
    at exports._exceptionWithHostPort (util.js:860:20)
    at Server._listen2 (net.js:1218:19)
    at listen (net.js:1267:10)
    at net.js:1376:9
    at doNTCallback3 (node.js:440:9)
    at process._tickCallback (node.js:346:17)
    at Function.Module.runMain (module.js:477:11)
    at startup (node.js:117:18)
    at node.js:951:3

The second argument of listen is not the domain name, is the address to listen on. listen的第二个参数不是域名,而是要监听的地址。 It could be something like 192.168.xx or 127.0.0.1 or 0.0.0.0 ( means all address. ). 可能是192.168.xx127.0.0.10.0.0.0 (表示所有地址。)。 The default is 127.0.0.1 . 默认值为127.0.0.1

Which means you should remove the second argument of listen . 这意味着您应该删除listen的第二个参数。

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

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