I managed to login to ubuntu and do some installation and ftp some image files(just to test if the network works). How can I view it using Public IP or Elastic IP from browser? I don't want to transfer the DNS yet because I am testing out the Node.js for now.
-
You want to serve the files with Node.js, or you want to view them in a static way (`http://dns-to-my-server/some_image.jpg`)? – Uri Agassi Feb 24 '14 at 20:55
-
@Uri Agassi Yes I want to view them in a static way like you say, to complete the whole learning circle. – sooon Feb 24 '14 at 23:44
4 Answers
I'm guessing this is to do with the NodeJS server definition
The default server.listen given in the examples
server.listen(1337, "127.0.0.1");
NodeJS will only listen to connections from 127.0.0.1.
To get it to respond to all requests, try the following setupthe host part is optional)
server.listen(1337);

- 96
- 2
-
Sorry I am rather new to the server side. Do you mind give me some example code? – sooon Feb 22 '14 at 12:12
-
1`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/');` Replace 8080 with your own code. The important part is the .listen(port,IP); if you don't specify this it will only listen to localhost (127.0.0.1) – StuartB Feb 24 '14 at 12:40
-
Sorry for the newbie question, but where do I do this code you provide? In node nano? – sooon Feb 24 '14 at 23:45
Launching an ubuntu instance on EC2 does not automatically make it a server. You need to actually run a web-server in order to see files from that computer on your browser.
For static files, you can use simple web server like python's SimpleHTTPServer or webfsd.
If you are planning to work with node.js, you might prefer writing a small Hello World in node.js instead:
// 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/");

- 36,848
- 14
- 76
- 93
-
This works for me thanks, but I finally decided to start from scratch with [this tutorial](http://techprd.com/setup-node-js-web-server-on-amazon-ec2/), just to see if I miss out anything important. – sooon Feb 25 '14 at 16:27
You need to allow the port where you are running node.js on the security group that your EC2 instance is using. Then you can access your site at http://<public ip of your server>:<port where node.js is running on>

- 58,485
- 12
- 111
- 141
-
Yes I already done that. I can connect with CLI and SFTP. But I am not sure how to make it work for browser. Anything else that I can check? – sooon Feb 22 '14 at 06:55
An EC2 instance isn't a web server by default.
sudo apt-get install httpd
should do the trick. You will then need to start the server by:
sudo service httpd start
Then I would test the working by creating index.html at the following location using the command.
sudo vim /var/www/html index.html
Default Security Group settings do not allow inbound traffic. If you go to the AWS EC2 console using: AWS EC2 Instance Console and EDIT the security group. Allow HTTP for all IP.
Now if you go to {https:// YOUR-PUBLIC-IP-ADDRESS/}, it should display the html contents of index.html. Images can be added on similar notes.

- 794
- 6
- 16