Flask deployment with nginx and uwsgi
23 Nov 2014Taking your applications from the development web server into a full application server environment is quite painless with nginx, uwsgi and virtualenv. This post will take you through the steps required to get an application deployed.
Server Setup
First of all, you’ll need to get your server in a state where it’s capable of serving HTTP content as well as housing your applications. If you’ve already got a server that will do this, you can skip this.
This will put all of the software required onto the server to house these applications.
Application setup with uWSGI
Each uWSGI application’s configuration is represented on the filesystem as an ini
file, typically found in /etc/uwsgi/apps-available
. Symlinks are established between files in this directory into /etc/uwsgi/apps-enabled
to tell the uwsgi
daemon that an application needs to be running.
The following is an example uWSGI configuration file that you can use as a template:
This will get our application housed by uWSGI. You can now enable this application:
Web server setup
Finally, we’ll get nginx to provide web access to our application. You may have specific web site files that you need to modify to do this, but this example assumes that you’re in control of the default
application.
Add the following section to /etc/nginx/sites-available/default
:
Reload your web server config, and you’re ready to go: