EC2实例的端口80上的IIS /节点服务器问题

服务器configuration完成后,我有一台IIS服务器在我的EC2实例的端口80上侦听。 我可以从我的弹性IP访问这个。 但是我closures了希望在端口80上启动节点服务器的IIS服务器。

现在,两个都不行! 我的节点应用程序侦听端口80,但不能从外部使用弹性IP访问。 我试图启动IISpipe理器中的IIS服务器,它看起来像打开。 但在实例(使用私有IP)或从外部访问不可访问。

我能做些什么来解决它?

谢谢

Server.js

/*******************************************************************************************/ /*CREATE AND START SERVER*/ /*******************************************************************************************/ var fs = require('fs'); var html = fs.readFileSync('./public/index.html'); var server=http.createServer(function(req,res){ //res.write(html); // load the single view file (angular will handle the page changes on the front-end) //res.end(); // application ------------------------------------------------------------- app.get('*', function(req, res) { res.sendfile('./public/index.html'); // load the single view file (angular will handle the page changes on the front-end) }); }); server.listen(80,'localhost'); 

我build议使用相同的密钥对和安全组来启动一个新的实例。 然后将弹性IP移到新实例上。

启动Node JS 假设AWS Linux AMI

 sudo yum update sudo yum upgrade sudo yum install gcc yum groupinstall "Development tools" wget -c https://nodejs.org/dist/v5.2.0/node-v5.2.0.tar.gz #This is to download the source code. tar -xzf node-v$ver.tar.gz cd node-v$ver ./configure && make && sudo make install 

然后你的app.js

 var port = process.env.PORT || 80, http = require('http'), fs = require('fs'), html = fs.readFileSync('index.html'); var index = require('./index'); var server = http.createServer(function (req, res) { console.log(req.method + "sdf " + req.url + res); if (req.method === 'POST') { var body = ''; req.on('data', function(chunk) { body += chunk; }); req.on('end', function () { res.writeHead(200, 'OK', {'Content-Type': 'text/plain'}); res.write (html); res.end(); }); } else { res.writeHead(200); res.write(html); res.end(); } }); server.listen(port); console.log('Server running at http://127.0.0.1:' + port + '/'); 

而你的index.html

 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <p>Hello</p> </body> </html> 

这只是一个非常简单的Node JS实例

对于更强大的设置,我会build议去EBS并启动他们的一个样本。 这很容易。

希望这可以帮助

更新

问题:用户试图创build监听端口80的http服务器,并且运行了快速格式

解决方法:使用http listen port或express – 两者同时不允许程序运行

你仍然有同样的问题,我在这里的评论中描述。

当你这样做时:

 server.listen(80,'localhost') 

您正在告诉服务器侦听来自本地主机的请求,这意味着您明确忽略了所有的外部请求。 只需删除该参数即可监听来自所有地址的请求:

 server.listen(80)