I have just deployed Flask on my free tier AWS EC2 instance. My main.py basic app runs just fine in the terminal, in the virtual environment that I created.
main.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def testprint():
print('''
text test
''')
testprint()
if __name__ == "__main__":
app.run(host='0.0.0.0', port='5000')
However, I cannot access it via port 5000, neither by using localhost nor my external IP address in the browser.
curl 127.0.0.1:5000
curl: (7) Failed to connect to 127.0.0.1 port 5000 after 0 ms: Couldn't connect to server
My Security Groups inbound rules look like this:
Python and Flask versions:
flask --version
Python 3.9.16
Flask 3.0.3
Werkzeug 3.0.3
Also running nginx version: nginx/1.24.0. There is no ufw on the instance.
Tried opening up port 5000 on the inbound rules.
based on the information provided these are the list of things that i'd make sure of,
/
, ie, 127.0.0.1:5000/
on your server localhost.btw, how & where have you configured nginx? anyways, you still would be able to hit directly if exposed, make sure nginx doesn't interfere with the port 5000, (ps: it doesn't by default)
happy to help further :)