【问题标题】:AWS EC2 ipaddressAWS EC2 IP 地址
【发布时间】:2014-03-23 18:39:07
【问题描述】:

我设法登录到 ubuntu 并进行了一些安装和 ftp 一些图像文件(只是为了测试网络是否正常)。如何从浏览器使用公共 IP 或弹性 IP 查看它?我还不想转移 DNS,因为我现在正在测试 Node.js。

【问题讨论】:

  • 您想使用 Node.js 提供文件,或者您想以静态方式查看它们 (http://dns-to-my-server/some_image.jpg)?
  • @Uri Agassi 是的,我想像你说的那样以静态的方式查看它们,以完成整个学习圈。

标签: ubuntu amazon-ec2 elastic-ip


【解决方案1】:

在 EC2 上启动 ubuntu 实例不会自动使其成为服务器。您需要实际运行一个网络服务器才能在您的浏览器上查看该计算机上的文件。

对于静态文件,您可以使用简单的 Web 服务器,例如 python's SimpleHTTPServerwebfsd

如果您打算使用 node.js,您可能更喜欢在 node.js 中写一个小的 Hello World

// Load the http module to create an http server.
var http = require('http');

// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.end("Hello World\n");
});

// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);

// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8000/");

【讨论】:

  • 这对我有用,谢谢,但我最终决定从 this tutorial 重新开始,看看我是否错过了任何重要的事情。
【解决方案2】:

我猜这与 NodeJS 服务器定义有关

示例中给出的默认server.listen

server.listen(1337, "127.0.0.1");

NodeJS 只会监听来自 127.0.0.1 的连接。

要让它响应所有请求,请尝试以下设置,主机部分是可选的)

server.listen(1337);

【讨论】:

  • 对不起,我对服务器端比较陌生。你介意给我一些示例代码吗?
  • var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(8080, "0.0.0.0"); console.log('Server running at http://0.0.0.0:8080/'); 将 8080 替换为您自己的代码。重要的部分是 .listen(port,IP);如果你不指定它只会监听 localhost (127.0.0.1)
  • 抱歉这个新手问题,但是我在哪里做你提供的这个代码?在节点纳米?
【解决方案3】:

您需要在您的 EC2 实例使用的安全组上允许您运行 node.js 的端口。然后您可以通过http://<public ip of your server>:<port where node.js is running on>访问您的网站

【讨论】:

  • 是的,我已经这样做了。我可以连接 CLI 和 SFTP。但我不确定如何使它适用于浏览器。还有什么我可以检查的吗?
【解决方案4】:
  1. 默认情况下,EC2 实例不是 Web 服务器。

    sudo apt-get install httpd

应该可以解决问题。 然后,您需要通过以下方式启动服务器:

sudo service httpd start

然后我将通过使用命令在以下位置创建 index.html 来测试工作。

sudo vim /var/www/html index.html
  1. 默认安全组设置不允许入站流量。如果您使用以下命令访问 AWS EC2 控制台: AWS EC2 Instance Console 并编辑安全组。允许所有 IP 使用 HTTP。

  2. 现在,如果您转到 {https://YOUR-PUBLIC-IP-ADDRESS/},它应该会显示 index.html 的 html 内容。 可以在类似的笔记上添加图片。

【讨论】:

    猜你喜欢
    • 2018-11-15
    • 2016-12-02
    • 1970-01-01
    • 2021-04-19
    • 2021-12-22
    • 2015-05-10
    • 2018-03-09
    • 1970-01-01
    • 2019-08-10
    相关资源
    最近更新 更多