Shubham Borghare
Shubham Borghare

Reputation: 31

How do I successfully deploy the flask app on ec2?

We created one web app in flask, and for users authentication we used the aws cognito hosted UI, and I am able to successfully run the app on my localhost.

But when I tried to deploy it on ec2 ubuntu using nginx server, I can only access the cognito hosted UI of my app, but after successful authentication in cognito, it is supposed to redirect to my dashboard page, which is happening when i am running the code on localhost, but on ec2 instance it says ERR_CONNECTION_REFUSED.

I tried below things:

  1. I setup the virtual environment, and installed all the packages.
  2. I setup the security group port as well in ec2.
  3. I setup the gunicorn configuration file.
  4. I setup the nginx, and congiguration file

I tried to run my project with below commands:

sudo systemctl stop project_name

sudo systemctl restart project_name

sudo systemctl daemon-reload

sudo systemctl start project_name

sudo systemctl enable project_name

sudo systemctl start nginx

sudo systemctl enable nginx

sudo systemctl restart nginx

Any guidance would be very helpful.

gunicorn configuration file

nginx configuration file

Upvotes: 0

Views: 625

Answers (2)

Chu_bot
Chu_bot

Reputation: 75

I know this is old, but I ran into this issue and it took me a while to solve. Just wanted to add this here for posterity.

All you need to do is delete the line

try_files $uri $uri/ =404:

in the sites-available/default file.

Upvotes: 0

Kartikey
Kartikey

Reputation: 80

Try running the app by passing the host like this in your app

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

Upvotes: 1

Related Questions