Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.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 EC2实例端口80上的IIS/节点服务器问题_Node.js_Amazon Web Services_Express_Amazon Ec2_Aws Ec2 - Fatal编程技术网

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

Node.js EC2实例端口80上的IIS/节点服务器问题,node.js,amazon-web-services,express,amazon-ec2,aws-ec2,Node.js,Amazon Web Services,Express,Amazon Ec2,Aws Ec2,在服务器配置之后,我让一台IIS服务器在EC2实例的端口80上侦听。我可以从我的弹性IP访问这个。 但我关闭了IIS服务器,希望在端口80上启动节点服务器 现在,两者都不起作用!!我的节点应用程序侦听端口80,但无法使用弹性IP从外部访问。 我尝试在IIS管理器中启动IIS服务器,它看起来好像打开了。但它不能在实例内(使用私有IP)或从外部访问 我能做些什么来修复它 谢谢 Server.js /***************************************************

在服务器配置之后,我让一台IIS服务器在EC2实例的端口80上侦听。我可以从我的弹性IP访问这个。 但我关闭了IIS服务器,希望在端口80上启动节点服务器

现在,两者都不起作用!!我的节点应用程序侦听端口80,但无法使用弹性IP从外部访问。 我尝试在IIS管理器中启动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');

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

要启动节点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
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 + '/');
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <p>Hello</p>
    </body>
</html>
然后你的app.js

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
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 + '/');
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <p>Hello</p>
    </body>
</html>
以及您的index.html

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
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 + '/');
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <p>Hello</p>
    </body>
</html>

你好

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

为了获得更健壮的设置,我建议您转到EBS并启动其中一个示例。这容易多了

希望这有帮助

更新 问题:用户试图在端口80上创建侦听的
http
服务器,并且运行了express format


解决方案:使用
http
listen to port或
express
-两者同时使用将不允许程序运行

您仍然存在与中所述相同的问题

当您这样做时:

server.listen(80,'localhost')
您告诉服务器侦听来自本地主机的请求,这意味着您显式地忽略了所有外部请求。只需删除该参数即可侦听来自所有地址的请求:

server.listen(80)

您是否尝试在公共/弹性IP或专用IP上通过ssh访问服务器?此外,就架构而言,IIS和节点有点交叉。很明显,我建议将来运行一个或另一个,但听起来您可能有两件事在端口80上启动侦听器。与“不工作/正在运行”相反,您是否尝试完全卸载节点?我无法通过telnet建立连接。我一直在使用RDP。我只想运行节点服务器。我只是使用IIS服务器来测试端口80。我不需要它。是的,在我看来很正常,有用吗?您使用的是EC2还是EBS?我看看能不能帮你写一篇简短的评论。另外,你用的是Mac还是PC?只是出于好奇。这两种平台显然都是完美的,但如果你使用的是Mac,我强烈推荐一个名为CodeRunner2的程序。它可以运行您的节点JS代码来创建侦听端口的本地主机,以便您可以在浏览器中测试它。这可能是我使用过的最好的整体开发程序——整天都在使用它。如果你使用PC,我相信你也可以用类似的方式来做,但我只使用Mac和Ubuntu。有时候,在本地机器上运行这些东西会更容易理解。明白了,听起来你的服务器实际上运行在正确的端口上。我注意到您正在指定Express的文件夹路径。你为什么不试着把它限制在
('express')
另外,你试过expressgenerator模块吗?首先,我用applicationgenerator启动了我的节点项目。那真是太好了!!其次,在代码中添加http服务器后,我的应用程序不再加载到浏览器上。我用我用来启动http服务器的代码更新了帖子哦!是的,我刚开始的时候也有这个问题。快速或创建服务器,一个或另一个基本上。我的问题是越来越奇怪了。我理解你的建议,也照做了。现在可以使用不同的IP(我使用私有IP和127.0.0.0)从实例浏览器访问侦听端口80的节点服务器。但它仍然没有响应公共/弹性IP。它给了我一个超时错误。