[Flask] Deploying Flask on Debian

Anthony Ford ford.anthonyj at gmail.com
Thu May 5 13:30:20 EDT 2016


Hey Alex,

Congrats on the progress so far. Let me see if I can clarify some things
for you

1. Is Mod_WSGI only for Apache? Should I stick with UWSGI, given that I'm
> using Nginx?
>

Yes. Mod_WSGI is essentially a router that passes the request from Apache
(the url requested, HTTP headers,  etc), and will accept the response from
your app and pass it back to Apache to send to the client. If you are using
Nginx, yes you should stick with uWSGI.



> 2. I read that UWSGI is also a web server, and that it's suggested to use
> UWSGI with Nginx behind it. This seems more complicated than I expected.
> Did I understand it right? Is this a choice, or the only/best way to set
> things up?
>

uWSGI can act as a standalone web-server for HTTP/S (
http://uwsgi-docs.readthedocs.io/en/latest/HTTP.html#the-uwsgi-http-https-router).
If you have a heavy site (i.e. hundreds+ of active users), you will waste
efficiency and capacity by having uWSGI handle your static files (i.e. your
JS, images, etc.), so it is recommended to hide uWSGI behind an HTTP server
(i.e. Nginx) and let it handle the static loads since they are
significantly better at serving static files.

No, you do not have to do this if you are building an internal or low use
site (but if the site is public, be prepared for traffic spikes that can
bring your site down, like slash-doting or reddit hug-of-deaths). Use the
`--http` option as suggesting in the above link.



> 3. When all this is up and running, will views be relative to my app, or
> app/templates? That is, should I set the document root in Nginx to be
> /var/www/myApp, or /var/www/myApp/templates? The myApp folder has run.py,
> config.py, static/, and templates/.


If you are serving your app behind Nginx, the main document root (or
location in nginx parlance), i.e. /, would be your app in wsgi (the
uwsgi_pass section). The only thing Nginx should serve would be your static
files in `static/` (which should be served as `/static/`.

I've stuck together a gist with some sanitized config files from a recent
project. You can find them here:
https://gist.github.com/ajford/32ca09c1bdb67e2211247f189aa2ae9a

It's got some complexity (the vars in the wsgi definitions) because this
was running on an applications server with three different Flask based apps
running behind Nginx. In my case, while the number of users was low (~10
max, more like a single user concurrent), I only had the one server
available, so they were placed behind Nginx to handle the virtual server
names (so the different apps wouldn't crash when serving). This may be
possible using uwsgi stand-alone, but I already knew how to do it in Nginx.

Hope this helps!



Anthony Ford,
KF5IBN,
ford.anthonyj at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20160505/1633a3ed/attachment-0001.html>


More information about the Flask mailing list