0

ec2 instance is not publically available

I have a simple flask server open to port 80

there is even a public ip address but if I curl remotely to it connection get refused

curl result screenshot

but strangely ssh works just fine

and if I curl to public ip inside ec2 ssh it works

tried editing security group inboud rules but doesn't work...

googled bunch but all solutions say to edit inbound rules but it doesn't work for me...

am I doing something wrong?

inbound rule screenshot

kjetil b halvorsen
  • 1,206
  • 2
  • 18
  • 28
  • When you say "if I curl to public ip inside ec2 ssh it works", do you mean the public IP or the public hostname? The default VPC DNS resolver, assuming that's what you're using, will resolve the EC2 instance's public hostname to its private IP, not its public IP. – jarmod Dec 14 '22 at 15:30
  • Also, are you [running](https://stackoverflow.com/questions/7023052/configure-flask-dev-server-to-be-visible-across-the-network) `app.run(host= '0.0.0.0')`? – jarmod Dec 14 '22 at 15:43
  • oh my god this was the case!! thx!! host was set to localhost ;) – Hajin Chung Dec 14 '22 at 21:37

1 Answers1

0

The most common reason for this is that your Flask app is listening on localhost only, which is the default, and so is not reachable from outside the machine it's running on.

To fix this, make the server externally visible, by using:

app.run(host='0.0.0.0')
jarmod
  • 71,565
  • 16
  • 115
  • 122