cgi.rst
This file
Path
docs/deploying/cgi.rst
61 lines · 2.0 KiB
Last changed by
Merge pull request #654 from untitaker/print_in_cgi2Armin Ronacherbefore adoption7ec45c2
History of this fileTake it
The walk stopped after 200 commits: lines older than 56afafa point at it.
Do not break extension tests if tested with installed extensions.Armin Ronacherbefore adoption56afafa
lines 1–18why, one step back1CGI2===34If all other deployment methods do not work, CGI will work for sure.5CGI is supported by all major servers but usually has a sub-optimal6performance.78This is also the way you can use a Flask application on Google's `App9Engine`_, where execution happens in a CGI-like environment.1011.. admonition:: Watch Out1213 Please make sure in advance that any ``app.run()`` calls you might14 have in your application file are inside an ``if __name__ ==15 '__main__':`` block or moved to a separate file. Just make sure it's16 not called because this will always start a local WSGI server which17 we do not want if we deploy that application to CGI / app engine.18Merge pull request #647 from untitaker/print_in_cgiKenneth Reitzbefore adoption8131496
line 19why, one step back19 With CGI, you will also have to make sure that your code does not containMerge pull request #654 from untitaker/print_in_cgi2Armin Ronacherbefore adoption7ec45c2
line 20why, one step back20 any ``print`` statements, or that ``sys.stdout`` is overridden by somethingMerge pull request #647 from untitaker/print_in_cgiKenneth Reitzbefore adoption8131496
lines 21–22why, one step back21 that doesn't write into the HTTP response.22Do not break extension tests if tested with installed extensions.Armin Ronacherbefore adoption56afafa
lines 23–41why, one step back23Creating a `.cgi` file24----------------------2526First you need to create the CGI application file. Let's call it27`yourapplication.cgi`::2829 #!/usr/bin/python30 from wsgiref.handlers import CGIHandler31 from yourapplication import app3233 CGIHandler().run(app)3435Server Setup36------------3738Usually there are two ways to configure the server. Either just copy the39`.cgi` into a `cgi-bin` (and use `mod_rewrite` or something similar to40rewrite the URL) or let the server point to the file directly.41Merge branch 'master' of github.com:mitsuhiko/flaskArmin Ronacherbefore adoption2e816f5
line 42why, one step back42In Apache for example you can put something like this into the config:Do not break extension tests if tested with installed extensions.Armin Ronacherbefore adoption56afafa
lines 43–46why, one step back4344.. sourcecode:: apache4546 ScriptAlias /app /path/to/the/application.cgiMerge branch 'master' of github.com:mitsuhiko/flaskArmin Ronacherbefore adoption2e816f5
lines 47–57why, one step back4748On shared webhosting, though, you might not have access to your Apache config.49In this case, a file called `.htaccess`, sitting in the public directory you want50your app to be available, works too but the `ScriptAlias` directive won't51work in that case:5253.. sourcecode:: apache54 55 RewriteEngine On56 RewriteCond %{REQUEST_FILENAME} !-f # Don't interfere with static files57 RewriteRule ^(.*)$ /path/to/the/application.cgi/$1 [L]Do not break extension tests if tested with installed extensions.Armin Ronacherbefore adoption56afafa
lines 58–61why, one step back5859For more information consult the documentation of your webserver.6061.. _App Engine: http://code.google.com/appengine/