The Flask docs for this take you 80% of the way there.
First, let’s make sure uWSGI runs independent of nginx.
The docs tell us to write this:
There’s two problems with this:
First, you may get some error that it doesn’t find flask if you are using a virtual environment (which you should).
Second, nginx may not be able to read the file later if the permissions don’t let it.
So I had to adapt it to this:
Now, install nginx with apt-get install nginx. Change the /etc/nginx/sites-available/default to read:
1 2 3 4 5 6 7 8 9
Now symlink the file above to the enabled one, because that’s how nginx works:
Start nginx with ‘/etc/init.d/nginx restart’
Go to a browser and try it out. Yay!
But what if you want to restart the server? nginx will restart, but your uWSGI will not. We’ll use supervisord for that.
We need to set up the /etc/supervisord.conf to tell supervisor what to do:
Now, kill your supervisor, start it again, and your Flask app be running ad infinitum.
1 2 3
Here’s another supervisor sample config file to get you inspired.
Hope this helps.