cgi.rst
This file
Path
docs/deploying/cgi.rst
50 lines · 1.6 KiB
Last changed by
Merge branch 'master' of github.com:mitsuhiko/flaskArmin Ronacherbefore adoption5ecf01d
History of this fileTake it
The walk stopped after 200 commits: lines older than 55040d3 point at it.
Added Adam Zapletal and Christopher Grebs to AUTHORs file.Armin Ronacherbefore adoption55040d3
lines 1–40why, one step back1CGI2===34If all other deployment methods do not work, CGI will work for sure. CGI5is supported by all major servers but usually has a less-than-optimal6performance.78This is also the way you can use a Flask application on Google's9`App Engine`_, there however the execution does happen in a CGI-like10environment. The application's performance is unaffected because of that.1112.. admonition:: Watch Out1314 Please make sure in advance that your ``app.run()`` call you might15 have in your application file, is inside an ``if __name__ ==16 '__main__':`` or moved to a separate file. Just make sure it's not17 called because this will always start a local WSGI server which we do18 not want if we deploy that application to CGI / app engine.1920.. _App Engine: http://code.google.com/appengine/2122Creating a `.cgi` file23----------------------2425First you need to create the CGI application file. Let's call it26`yourapplication.cgi`::2728 #!/usr/bin/python29 from wsgiref.handlers import CGIHandler30 from yourapplication import app3132 CGIHandler().run(app)3334If you're running Python 2.4 you will need the :mod:`wsgiref` package. Python352.5 and higher ship this as part of the standard library.3637Server Setup38------------3940Usually there are two ways to configure the server. Either just copy theMerge branch 'master' of github.com:mitsuhiko/flaskArmin Ronacherbefore adoption5ecf01d
line 41why, one step back41`.cgi` into a `cgi-bin` (and use `mod_rewrite` or something similar toAdded Adam Zapletal and Christopher Grebs to AUTHORs file.Armin Ronacherbefore adoption55040d3
lines 42–50why, one step back42rewrite the URL) or let the server point to the file directly.4344In Apache for example you can put a like like this into the config:4546.. sourcecode:: apache4748 ScriptAlias /app /path/to/the/application.cgi4950For more information consult the documentation of your webserver.