Ritish Gupta
Ritish Gupta

Reputation: 43

Why my website hosted on aws refuses to connect?

I have a node app which runs on localhost perfectly, I hosted it on AWS ec2 instance on port 80 and it worked fine too, after 7 days of inactivity when I searched public IP address of my ec2 instance(on any browser), it says <public_ipv4> refused to connect.

Here are a few things I did for troubleshooting which I read from AWS forums but not getting any luck:

  1. deleted the node_modules/ directory and reinstalled using npm install command

  2. Have correctly allowed HTTP traffic on port 80 inside inbound rules of security groups for that instance(i have only one instance running)

  3. Ran netstat -nplt | grep 80 , which gave me output :

    tcp6 0 0 :::80 :::* LISTEN

  4. I have added a script in package.json file, through which app.js file will run

In my app.js file i am listening to port 80:

app.listen(80, async  function(){
  console.log("server has started");
})

What else am I missing?

Screenshot of inbound rules :enter image description here

Upvotes: 2

Views: 1308

Answers (3)

Ritish Gupta
Ritish Gupta

Reputation: 43

In my app.js file i have used port 80 :

app.listen(80, async  function(){
  console.log("server has started");
})

but when i changed port number to 3000 in app.listen , it worked , i dont't know how did this happen though. There was no issue with security groups.

Upvotes: 1

vkg
vkg

Reputation: 1859

See if the steps below helps.

  1. Did you stop your ec2 instance start and it again if you did it would have changed your public ip if that is case use the new public ip.
  2. Check your security groups attached to the ec2 instance if it allows in bound traffic on port 80. enter image description here
  3. If the first step does not work connect to your ec2 instance and run a curl command to see if your app is running.

Upvotes: 2

Ravindra Bagale
Ravindra Bagale

Reputation: 17655

it seems you have allowed only IP v6 address on Inbound traffic of Security Groups..

Not added allow permission for IPv4 address..

Add below rule

HTTP tcp 0.0.0.0/0  80

if you have added both rule ( IPV4 and IPV6) then

sudo netstat -tnlp | grep :80  

should show below both lines..

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN 
tcp6       0      0 :::80                   :::*                    LISTEN  

but in your case it showing only tcp6

Upvotes: 2

Related Questions