node.js install on Amazon EC2
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 开发者_如何学Pythonto :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.
You need to open up port 8000 in your security group.
If you've got the EC2 command line tools installed, try running:
$ ec2-authorize default -p 8000
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:
- Login to the AWS console
- Select Amazon EC2 in the top bar
- Click on Security Groups in the menu on the left
- Click on the security group that you assigned to your EC2 instance (probably just default)
- In the bottom window pane, click on the Inbound tab
- Set Port range: to 8000 and leave the other two inputs as they are
- Click Add Rule
Within the security group associated with the EC2 instance, make sure you have port 8000 open to your IP or to the public.
Check the following:
- That you are allowing access from all ips to port 8000 in the security group
- That you have modified the CORRECT security group (e.g., quicklaunch-1) and not, say, quicklaunch-2. I've edited the wrong one more times than I care to admit.
- That you have opened port 8000 on the Linux firewall
- That your server is actually running (you should see "Listening on port 8000" in the command line).
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.
精彩评论