简体   繁体   中英

Deploy simple server using Flask on AWS

I'm using this Python code to see if I can view the simple AWS server however, I'm still not able to load the webpage properly.

from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
    return "It works!"

if __name__ == '__main__':
    app.run(port=80, host='0.0.0.0')

In AWS, inbound:

HTTP TCP port 80 with a source of: 0.0.0.0/0
SSH TCP port 22 with a source of: 0.0.0.0/0

Outbound - everything is allowed.

I'm seeing no errors on terminal when I start the program. The console says Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) so I'm trying to load http://ubuntu@ec2-IPADDRESS.compute-1.amazonaws.com:5000

Flask defaults to binding to 127.0.0.1:5000 .

If you're trying to access http://ubuntu@ec2-IPADDRESS.compute-1.amazonaws.com:5000 , you'll need to have port 5000 opened in the inbound firewall rules and bind to 0.0.0.0 instead of 127.0.0.1.

You can not use port 80 for your web application. Let it run on default port then host your web application by mod_wsgi or uWSGI... Check the deployment options here: http://flask.pocoo.org/docs/0.12/deploying/ .

Imo: better if you deploy your application on AWS Elastic Beanstalk. Give me a shout if you need a sample project.

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