bundled/flask/docs/deploying/cgi.rst @ 16e0bcd4f854

Switch to the new hg spanset API

This api was introduced in 3.2, and the indexation is not supported anymore (probably since
3.4)

Patch provided by David Douard
(see https://bitbucket.org/sjl/hg-review/pull-requests/8/better-handling-of-obsolescence-markers/diff#comment-8174971)
author Christophe de Vienne <christophe@cdevienne.info>
date Fri, 19 Aug 2016 18:21:28 +0200
parents f33efe14bff1
children (none)
CGI
===

If all other deployment methods do not work, CGI will work for sure.  CGI
is supported by all major servers but usually has a less-than-optimal
performance.

This is also the way you can use a Flask application on Google's
`App Engine`_, there however the execution does happen in a CGI-like
environment.  The application's performance is unaffected because of that.

.. admonition:: Watch Out

   Please make sure in advance that your ``app.run()`` call you might
   have in your application file, is inside an ``if __name__ ==
   '__main__':`` or moved to a separate file.  Just make sure it's not
   called because this will always start a local WSGI server which we do
   not want if we deploy that application to CGI / app engine.

.. _App Engine: http://code.google.com/appengine/

Creating a `.cgi` file
----------------------

First you need to create the CGI application file.  Let's call it
`yourapplication.cgi`::

    #!/usr/bin/python
    from wsgiref.handlers import CGIHandler
    from yourapplication import app

    CGIHandler().run(app)

Server Setup
------------

Usually there are two ways to configure the server.  Either just copy the
`.cgi` into a `cgi-bin` (and use `mod_rewrite` or something similar to
rewrite the URL) or let the server point to the file directly.

In Apache for example you can put a like like this into the config:

.. sourcecode:: apache

    ScriptAlias /app /path/to/the/application.cgi

For more information consult the documentation of your webserver.