Deploying a Python webapp with Nginx, Gunicorn and Flask

Setting up a stack

    So I’ve decided to begin developing some sort of web application. Not sure exactly what yet, but would like to get the server set up out of the way. Ive looked over a few possible solutions such as a server(less) LAMP stack, niche hosts such as pythonanywhere and heroku.

    I settled on Nginx because WSGI is built-in (nginx docs) and it seems simpler to configure than apache. A conversation with the python discord chat from reddit helped alleviate some suspicions.

Short code list of commands for base server configuration here

So after some time working on TwitWords, I realized what my issue was. The reason I was getting dependency issues in my error log is -guess what- because I had dependency issues in my program. I had pip installed all my libraries, but forgot that I needed to run nltk.download() to get all the required data for NLTK.

Derp.

 

    This was after wasting many hours attempting to get a LAMP stack running on AWS to serve a python Dash application. Apache just wasn’t digging it. I was able to get the hello world example apps running for both Flask and Dash on the development server, and (briefly) had my IP point at it, which also worked fine. For some reason though I would fail for suspicious reasons while attempting to deploy my own app, receiving 500 internal server error . I scoured logs in /var/log/apache2 for my flask app and had weird dependency issues causing errors, even though I was able to import them when opening python at command line.

I eventually switched my host for this app out for Digital Ocean (Can’t really beat a static $5.00/mo VPS.) I plan to set a CNAME record in route 53 upon completion to have app.ryanpskiles.com point at the digital ocean droplet. (ryanpskiles.com VPS runs Amazon Web Services Elastic Cloud Compute)

Leave a Comment