Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.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
Amazon ec2 无法命中托管在EC2实例上的简单节点web服务器_Amazon Ec2_Aws Security Group - Fatal编程技术网

Amazon ec2 无法命中托管在EC2实例上的简单节点web服务器

Amazon ec2 无法命中托管在EC2实例上的简单节点web服务器,amazon-ec2,aws-security-group,Amazon Ec2,Aws Security Group,无法访问AWS中ubuntu EC2上托管的简单节点web服务器。但我看不出我错过了什么!我在AWS中提供了以下屏幕截图-我缺少什么?请帮忙!。 非常感谢, 节点代码 const http = require('http'); const hostname = '127.0.0.1'; const port = 8080; const server = http.createServer((req, res) => { res.statusCode = 200; res.set

无法访问AWS中ubuntu EC2上托管的简单节点web服务器。但我看不出我错过了什么!我在AWS中提供了以下屏幕截图-我缺少什么?请帮忙!。 非常感谢,

节点代码

const http = require('http');

const hostname = '127.0.0.1';
const port = 8080;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});
Server running at http://127.0.0.1:8080/
命令提示

$ node index.js 
命令提示响应

const http = require('http');

const hostname = '127.0.0.1';
const port = 8080;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});
Server running at http://127.0.0.1:8080/
EC2实例

const http = require('http');

const hostname = '127.0.0.1';
const port = 8080;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});
Server running at http://127.0.0.1:8080/

安全设置

弹性IP设置

浏览器

http://"Public DNS (IPv4) value":8080/ 
更新

const http = require('http');

const hostname = '127.0.0.1';
const port = 8080;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});
Server running at http://127.0.0.1:8080/

选择类型时,请选择“自定义TCP规则”:

然后在端口范围字段中输入8080

编辑

然而,这只是你的一部分。如果您注意到,您的服务器正在侦听IP地址
127.0.0.1
。这意味着它不需要倾听外界的声音,只需要
localhost
。要在服务器计算机之外访问它,您需要将代码更改为:

const http = require('http');

const hostname = '0.0.0.0';
const port = 8080;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

更改是,您现在正在侦听“所有接口”,而不是本地主机。

您已经在安全组中打开了端口80。您的节点服务器使用哪个端口?是的,我应该选择哪个下拉值来更改端口号?“HTTP”是固定在80I上的,我已经做了更改,但没有什么不同,我已经将更改作为屏幕截图包含在我的原始问题中。这很奇怪,我确信我的另一个EC2具有相同的节点服务器代码,它工作了,但感谢您让它工作了。您是否在服务器前面有类似Apache或Nginix的东西,代理?我想我有一个负载平衡器,现在你提到了(EC2负载平衡/负载平衡器选项)