【发布时间】:2025-12-29 22:05:11
【问题描述】:
过去 3-4 天我试图在亚马逊微型实例上运行 nodejs 服务器,但没有成功。
我学习了很多教程,但我无法让服务器正常工作(所以当它在浏览器中访问或在 powerShell 中 curl 并看到简单的 hello world 时)。
这是我尝试过的最后 3 个教程:
http://iconof.com/blog/how-to-install-setup-node-js-on-amazon-aws-ec2-complete-guide/ http://techprd.com/setup-node-js-web-server-on-amazon-ec2/ http://devblog.daniel.gs/2014/01/deploying-node-apps-on-aws-ec2-with.html
我试过 ubuntu/amazon linux。
我也关注了http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html,只是想看看一般流程是如何运作的,而且效果很好。
我达到了这样的地步:sudo node filename.js
并且服务器运行。
但是,当我尝试访问或卷曲它时。它不起作用。当我 ping 它时,它 ping 很好。
在亚马逊中,我将安全组设置为基本上允许这样的一切:
在 linux 中,我跟随:https://help.ubuntu.com/community/IptablesHowTo?action=show&redirect=Iptables 打开我试图监听的端口,但什么也没有。
当我输入:sudo service iptables status 我得到:
1 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpts:1337:1347
2 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpts:1338:1348
3 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:10000
请记住,我不是一个精通服务器的人。
任何帮助将不胜感激。
更新:要启动我的节点服务器,我使用 nodejs.org 中的基本代码:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
这正是我的文件的样子
【问题讨论】:
-
in amazon i set the security to basically allow everything是什么意思?应用于该实例的安全组的设置是什么? -
发布更新我的安全组的样子
-
你能在服务运行时从那台机器上 curl localhost 吗?如果不是,则该服务不起作用。如果是,则该端口可能不是列出的端口之一。
-
打开两个putty终端,一个运行node js,另一个输入curl localhost:1337返回hello world
-
酷。 “sudo iptables -L”报告什么?
标签: node.js curl amazon-web-services amazon-ec2 amazon-s3