I have my flask app running on ec2 instance with nginx and gunicorn3. The problem that I have is the following.
When I SSH into the EC2 machine and start the Gunicorn server gunicorn3 app:app
, all routes work fine and I can use then. But, after I close my terminal window, only few routes work and others don’t. (Out of 20 routes, only 3-4 work). I am using MongoDB database but that is not the problem because some routes that have MongoDB code work perfectly fine, while others that also have MongoDB code don’t.
Any help would be awesome.
Thank You
2
Answers
The answer is to add -daemeon when running
gunicorn3 app:app
. So the full command isgunicorn3 app:app --daemeon
.The best way to check the problem is to inspect logs, make sure you have enabled logs in nginx and gunicorn and you will be able to backtrack what is happening behind the scenes. Also make sure to run gunicorn via supervisor, in any case if the process gets killed it will be auto-restarted.
Reference :
https://medium.com/ymedialabs-innovation/deploy-flask-app-with-nginx-using-gunicorn-and-supervisor-d7a93aa07c18
https://medium.com/swlh/deploying-django-apps-for-production-on-ubuntu-server-18-04-using-gunicorn-supervisor-nginx-846c3c4099c0