Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何让部署在AWS云上的NodeJS服务器上线?_Node.js_Amazon Web Services_Ubuntu 14.04 - Fatal编程技术网

Node.js 如何让部署在AWS云上的NodeJS服务器上线?

Node.js 如何让部署在AWS云上的NodeJS服务器上线?,node.js,amazon-web-services,ubuntu-14.04,Node.js,Amazon Web Services,Ubuntu 14.04,我对NodeJS是新手。 我有下面的helloworld代码 var http = require("http"); http.createServer(function(request, response) { response.writeHead(200, {'Content-Type': 'text/plain'}); response.end('Hello World!\n I am the AWS cloud'); }).listen(8081); consol

我对NodeJS是新手。 我有下面的helloworld代码

var http = require("http");
http.createServer(function(request, response) {
    response.writeHead(200, {'Content-Type': 'text/plain'});
    response.end('Hello World!\n I am the AWS cloud');
    }).listen(8081);
console.log('Server is running at http://127.0.0.1:8081');
这段代码保存在我的AWS云上,它运行一个Ubuntu 14.04实例。 我已经在Ubuntu上安装了nodeJS。 当我运行代码时,它工作正常并显示控制台日志消息,但当我在另一台机器上打开web浏览器并键入时,它不工作

另外,当我按Ctrl+c停止脚本,然后再次执行时,它会显示以下错误消息:

Server is running at http://127.0.0.1:8081
events.js:85
      throw er; // Unhandled 'error' event
        ^
Error: listen EADDRINUSE
    at exports._errnoException (util.js:746:11)
    at Server._listen2 (net.js:1156:14)
    at listen (net.js:1182:10)
    at Server.listen (net.js:1267:5)
    at Object.<anonymous> (/home/ubuntu/NodeJSscripts/hw.js:17:22)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)

当我返回并更改端口号并再次运行脚本时,它会再次运行,不会抛出任何错误,但web浏览器仍然无法通过其公共IP连接到服务器。

您是否设置了安全组以允许在目标端口上向服务器发出请求?我不明白您在这里想问什么,但如果你是这个意思的话,我是在一个公司网络后面工作的。如果你使用的是EC2服务器,它带有一个预先配置的安全组。这就是我所说的安全组。因此,如果我正确配置安全组,上述问题将消失?可能,假设您的本地网络没有阻止它: