502 Bad Gateway Error in AWS ElasticBeanstalk while deploying Flask Application

Viewed 1615

I have created a Flask Application and deployed it in AWS ElasticBeanstalk. On accessing the EBS URL, I am getting the 502 Bad Gateway Error. nginx/1.16.1

On checking the error logs i see the following error:

[error] 3789#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 119.82.***.***, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "ec2-**-**-***-33.ap-south-1.compute.amazonaws.com"

I checked all the available solutions, but none of them work. Please help.

1 Answers

rename app.py to application.py, in app code to application. It worked for me.

from flask import Flask, render_template

application = Flask(__name__)

@application.route("/")
def index():
    return render_template('index.html')    

if __name__ == "__main__":
    application.run(debug=True)
Related