Re: [flask] Flask on a VPS
- From:
- Simon Sapin
- Date:
- 2010-07-31 @ 11:30
Hi
Le 31/07/2010 13:08, JimG a écrit :
> One thing I'm uncomfortable with is running the application from the
> public_html directory setup by the VPS? Is there a better place to put
> the wsgi file and the application code? Perhaps under the home
> directory of the user which the app runs as?
Python code, templates and the .wsgi file do not have to (and maybe
shouldn’t) be in a directory served by the web server. They can be
anywhere. I like the home dir as it makes shorter rsync/git URLs.
Assuming Apache/mod_wsgi,
The .wsgi file need to be somewhere « allowed » by Apache :
WSGIScriptAlias / /usr/local/www/wsgi-scripts/myapp.wsgi
<Directory /usr/local/www/wsgi-scripts>
Order allow,deny
Allow from all
</Directory>
(stolen from mod_wsgi docs)
Then, there are several ways to serve static files
* Let Flask do it. (Not efficient, but Just Works©)
* Enable X-Send-File in Flask and use mod_xsendfile in Apache
* Use Apache Aliases, mod_rewrite, symbolic links or something else to
make Apache serve them directly (most efficient, but require more
configuration work)
Regards,
--
Simon Sapin
Re: [flask] Flask on a VPS
- From:
- Simon Sapin
- Date:
- 2010-07-31 @ 11:48
Le 31/07/2010 13:30, Simon Sapin a écrit :
> Then, there are several ways to serve static files
> * Let Flask do it. (Not efficient, but Just Works©)
>
Actually, mod_wsgi does implement wsgi.file_wrapper to send static files
more efficiently:
http://code.google.com/p/modwsgi/wiki/FileWrapperExtension
Flask and Werkzeug use it when available, so this solution is not as bad
as moving megabytes of data around in pure Python.
Maybe I’ll do a proper benchmark later to compare all these solutions.
--
Simon Sapin
Re: [flask] Flask on a VPS
- From:
- Armin Ronacher
- Date:
- 2010-07-31 @ 16:33
Hi,
Unfortunately wsgi.cile_wrapper breaks if middlewares are part of the
stack. Because of that x-sendfile is strongly recomended.
Regards,
Armin
(sent from a handheld device)
On 31.07.2010, at 13:48, Simon Sapin <simon.sapin@exyr.org> wrote:
> Le 31/07/2010 13:30, Simon Sapin a écrit :
>> Then, there are several ways to serve static files
>> * Let Flask do it. (Not efficient, but Just Works©)
>>
>
> Actually, mod_wsgi does implement wsgi.file_wrapper to send static files
> more efficiently:
> http://code.google.com/p/modwsgi/wiki/FileWrapperExtension
>
> Flask and Werkzeug use it when available, so this solution is not as bad
> as moving megabytes of data around in pure Python.
>
> Maybe I’ll do a proper benchmark later to compare all these solutions.
>
> --
> Simon Sapin