Question

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.

Was it helpful?

Solution

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/");

OTHER TIPS

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);

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>

Node.js port

  1. 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
  1. 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.

  2. 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top