在 Amazon EC2 上安装 node.js
因此,我正在使用 ubuntu 8.04 在 amazon ec2 上安装 node.js,并运行 node sayhello.js
这是这段代码:
var sys = require('sys'),
http = require('http');
http.createServer(function (req, res) {
setTimeout(function () {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<br/><strong> Hello World!</strong>');
res.end();
sys.puts(sys.inspect(req, false));
}, 2000);
}).listen(8000);
sys.puts('Server running at http://ec2-174-12-132-193.compute-1.amazonaws.com:8000/');
我明白了
服务器运行于 http://ec2-174-12-132-193 .compute-1.amazonaws.com:8000/
正确显示在控制台中。
教程 说:在浏览器中转到 :8000,您应该会看到 Hello World!
我转到 http://ec2-174-12- 132-193.compute-1.amazonaws.com:8000/ (不是真实地址)但它不会加载(只是连接...)。该示例使用本地主机,公共域是否不正确或类似?
谢谢。
So I'm installing node.js on amazon ec2 with ubuntu 8.04, and and have run node sayhello.js
which is this code:
var sys = require('sys'),
http = require('http');
http.createServer(function (req, res) {
setTimeout(function () {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<br/><strong> Hello World!</strong>');
res.end();
sys.puts(sys.inspect(req, false));
}, 2000);
}).listen(8000);
sys.puts('Server running at http://ec2-174-12-132-193.compute-1.amazonaws.com:8000/');
I see
Server running at
http://ec2-174-12-132-193.compute-1.amazonaws.com:8000/
being displayed in the console correctly.
The tutorial says: go to :8000 in the browser and you should see Hello World!
I go to http://ec2-174-12-132-193.compute-1.amazonaws.com:8000/ (not the real address) but it doesn't load (just connecting...). The example uses localhost, is doing the public domain incorrect or some such?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要在安全组中开放端口 8000。
如果您已安装 EC2 命令行工具,请尝试运行:
这假定您使用的是默认安全组。如果没有,请将默认更改为您的安全组的名称。
如果您仅使用 Web 界面,请按照以下步骤操作:
You need to open up port 8000 in your security group.
If you've got the EC2 command line tools installed, try running:
This assumes that you're using the default security group. If not, change default to the name of your security group.
If you're just using the web interface follow these steps:
在与 EC2 实例关联的安全组中,确保您的 IP 或公众开放端口 8000。
Within the security group associated with the EC2 instance, make sure you have port 8000 open to your IP or to the public.
检查以下内容:
以下是有关如何在 Amazon EC2 上设置 Node.js Web 服务器的教程:http://www.lauradhamilton.com/how-to-set-up-a-nodejs-web-server-on-amazon-ec2
有点比你正在做的更复杂(因为它使用从 80 到 8080 的 ip 转发),但有关打开 Linux 防火墙的部分是相同的。
Check the following:
Here is a tutorial on how to set up a Node.js web server on Amazon EC2: http://www.lauradhamilton.com/how-to-set-up-a-nodejs-web-server-on-amazon-ec2
It's a bit more complicated than what you're doing (because it uses ip forwarding from 80 to 8080) but the part about opening the Linux firewall is the same.