librelist archives

« back to archive

[newbie] Use Flask with mod_fcgid?

[newbie] Use Flask with mod_fcgid?

From:
Gilles
Date:
2012-09-24 @ 16:15
Hello

I'd like to write a small Python web application and run it on a 
shared Apache web server which only supports mod_fcgid instead of mod_wsgi.

I'm somewhat clearer about how WSGI, SCGI, FastCGI do/work, and it 
seems like I'll need some application to connect mod_fcgid to my 
Flask-based application to support WSGI.

Is this correct?

Any feedback about combining mod_fcgid and Flask much appreciated.

Thank you.

Re: [flask] [newbie] Use Flask with mod_fcgid?

From:
Audrius Kažukauskas
Date:
2012-09-24 @ 16:27
On Mon, 2012-09-24 at 18:15:56 +0200, Gilles wrote:
> Hello
> 
> I'd like to write a small Python web application and run it on a
> shared Apache web server which only supports mod_fcgid instead of
> mod_wsgi.

Have you already checked Flask docs about FastCGI deployment?
http://flask.pocoo.org/docs/deploying/fastcgi/

-- 
Audrius Kažukauskas
http://neutrino.lt/

Re: [flask] [newbie] Use Flask with mod_fcgid?

From:
Gilles
Date:
2012-09-25 @ 12:29
At 18:27 24/09/2012, Audrius Kažukauskas wrote:
>Have you already checked Flask docs about FastCGI deployment?
>http://flask.pocoo.org/docs/deploying/fastcgi/

Thanks for the link. I'll check it out.

I'm also curious to know how those technologies 
work together: CGI, FastCGI, SCGI, WSGI. Does someone know?

Apparently, WSGI is at a higher level than the 
other, but otherwise, I'm clueless.

Thank you. 

Re: [flask] [newbie] Use Flask with mod_fcgid?

From:
Simon Sapin
Date:
2012-09-25 @ 13:17
Le 25/09/2012 14:29, Gilles a écrit :
> I'm also curious to know how those technologies
> work together: CGI, FastCGI, SCGI, WSGI. Does someone know?
>
> Apparently, WSGI is at a higher level than the
> other, but otherwise, I'm clueless.

Hi,

WSGI is a Python calling convention. Flask and other frameworks provide 
a callable object that takes 'environ' and 'start_headers' parameters 
and return an iterable of bytes. Various WSGI servers can call these 
objects to make requests.

http://www.python.org/dev/peps/pep-3333/


Some servers like gunicorn speak HTTP themselves on one side, and 
directly WSGI on the other side. Others like flup, rather than HTTP, 
speak FastCGI or SCGI (which are network protocols) with a front-end 
server like Apache, lighttpd or nginx.

Apache’s mod_wsgi is a bit special: both the Apache integration and the 
worker processes (assuming daemon mode) are managed by mod_wsgi. They 
speak an internal/private protocol together.

With CGI, the front-end server forks a new process for each request and 
runs an executable in it. Details of the request are passed as 
Unix-style environment variables, and the HTTP response should be 
printed on the standard output.

CGI is not advised nowadays as the whole start-up of Python, of the 
framework and importing all your code is repeated for every request, 
while other methods use long-lived Python processes.



In your original message, you say that only mod_fcgid is available. In 
this case apache’s mod_fcgid module is a client for the FastCGI 
protocol, and connects to a server with a unix or TCP socket. This 
server is a Python process running flup, which is a gateway between 
FastCGI and WSGI.

-- 
Simon Sapin

Re: [flask] [newbie] Use Flask with mod_fcgid?

From:
Todd Kennedy
Date:
2012-09-25 @ 13:24
A+ explanation of something not as clearly defined anywhere else. I
feel like this should be in the docs.

On Sep 25, 2012, at 9:19, Simon Sapin <simon.sapin@exyr.org> wrote:

> Le 25/09/2012 14:29, Gilles a écrit :
>> I'm also curious to know how those technologies
>> work together: CGI, FastCGI, SCGI, WSGI. Does someone know?
>>
>> Apparently, WSGI is at a higher level than the
>> other, but otherwise, I'm clueless.
>
> Hi,
>
> WSGI is a Python calling convention. Flask and other frameworks provide
> a callable object that takes 'environ' and 'start_headers' parameters
> and return an iterable of bytes. Various WSGI servers can call these
> objects to make requests.
>
> http://www.python.org/dev/peps/pep-3333/
>
>
> Some servers like gunicorn speak HTTP themselves on one side, and
> directly WSGI on the other side. Others like flup, rather than HTTP,
> speak FastCGI or SCGI (which are network protocols) with a front-end
> server like Apache, lighttpd or nginx.
>
> Apache’s mod_wsgi is a bit special: both the Apache integration and the
> worker processes (assuming daemon mode) are managed by mod_wsgi. They
> speak an internal/private protocol together.
>
> With CGI, the front-end server forks a new process for each request and
> runs an executable in it. Details of the request are passed as
> Unix-style environment variables, and the HTTP response should be
> printed on the standard output.
>
> CGI is not advised nowadays as the whole start-up of Python, of the
> framework and importing all your code is repeated for every request,
> while other methods use long-lived Python processes.
>
>
>
> In your original message, you say that only mod_fcgid is available. In
> this case apache’s mod_fcgid module is a client for the FastCGI
> protocol, and connects to a server with a unix or TCP socket. This
> server is a Python process running flup, which is a gateway between
> FastCGI and WSGI.
>
> --
> Simon Sapin

Re: [flask] [newbie] Use Flask with mod_fcgid?

From:
Simon Sapin
Date:
2012-09-25 @ 14:04
Le 25/09/2012 15:24, Todd Kennedy a écrit :
> I feel like this should be in the docs.

Feel free to make a pull request ;)
The docs are in the same repo/branch as Flask’s code.

-- 
Simon Sapin

Re: [flask] [newbie] Use Flask with mod_fcgid?

From:
Gilles
Date:
2012-09-26 @ 16:21
At 15:17 25/09/2012, you wrote:
>Some servers like gunicorn speak HTTP themselves on one side, and 
>directly WSGI on the other side. Others like flup, rather than HTTP, 
>speak FastCGI or SCGI (which are network protocols) with a front-end
>server like Apache, lighttpd or nginx.

Thanks much for the clarification. Things are clearer now.

So since the shared Apache I have only supports mod_fcgid, it looks 
like I'll have to run something like Flup to sit between Apache and 
the WSGI Python application through FastCGI so it translates between 
HTTP and WSGI and back.

In an ideal world, for moderately loaded web/app setting, what web 
server and WSGI server would you recommend? What about NGINX and uWSGI?

Thank you. 

Unsubscribe

From:
Ali Paknejad
Date:
2012-09-24 @ 16:47