简体   繁体   中英

Amazon EC2 instance not able to make HTTP connection

I am new to Amazon EC2 so please excuse me if I'm asking a stupid question. I created an instance using "Amazon Linux AMI" and installed NodeJS in it.

I added the following IP table entry for forwarding all the request from port 80 to 3000.

sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000

and I created a hello world script to test this installation.

var http = require("http");

http.createServer(function (request, response) {
  // Send the HTTP header
  // HTTP Status: 200 : OK
  // Content Type: text/plain
  response.writeHead(200, {'Content-Type': 'text/plain'});

  // Send the response body as "Hello World"
  response.end('Hello World\n');
}).listen(3000);

// Console will print the message
console.log('Server running at http://127.0.0.1:3000/');

Here the issue is when I try to ping to my instance for command line, the request is timing out

ping ec2-52-26-59-26.us-west-2.compute.amazonaws.com

PING ec2-52-26-59-26.us-west-2.compute.amazonaws.com (52.26.59.26): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2

How I can fix this issue?

You need to update the EC2 instance's security group to allow:

protocol: TCP, port: 3000, source: My IP

Or you could change the source to Everywhere if you want to open it up to everyone on the internet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM