Skip to content
Myr

cgi.rst

This file

Path

docs/deploying/cgi.rst

57 lines · 1.8 KiB

Last changed by

Merge branch 'master' of github.com:mitsuhiko/flaskArmin Ronacherbefore adoption2e816f5

History of this file

Take it

The walk stopped after 200 commits: lines older than b40af3c point at it.

Updated the documentation to show how to set cookies for not yet existing responsesArmin Ronacherbefore adoptionb40af3c

lines 1–37why, one step back
1CGI
2===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.1819Creating a `.cgi` file20----------------------2122First you need to create the CGI application file. Let's call it23`yourapplication.cgi`::2425 #!/usr/bin/python26 from wsgiref.handlers import CGIHandler27 from yourapplication import app2829 CGIHandler().run(app)3031Server Setup32------------3334Usually there are two ways to configure the server. Either just copy the35`.cgi` into a `cgi-bin` (and use `mod_rewrite` or something similar to36rewrite the URL) or let the server point to the file directly.37

Merge branch 'master' of github.com:mitsuhiko/flaskArmin Ronacherbefore adoption2e816f5

line 38why, one step back
38In Apache for example you can put something like this into the config:

Updated the documentation to show how to set cookies for not yet existing responsesArmin Ronacherbefore adoptionb40af3c

lines 39–42why, one step back
39
40.. sourcecode:: apache4142 ScriptAlias /app /path/to/the/application.cgi

Merge branch 'master' of github.com:mitsuhiko/flaskArmin Ronacherbefore adoption2e816f5

lines 43–53why, one step back
43
44On shared webhosting, though, you might not have access to your Apache config.45In this case, a file called `.htaccess`, sitting in the public directory you want46your app to be available, works too but the `ScriptAlias` directive won't47work in that case:4849.. sourcecode:: apache50 51 RewriteEngine On52 RewriteCond %{REQUEST_FILENAME} !-f # Don't interfere with static files53 RewriteRule ^(.*)$ /path/to/the/application.cgi/$1 [L]

Updated the documentation to show how to set cookies for not yet existing responsesArmin Ronacherbefore adoptionb40af3c

lines 54–57why, one step back
54
55For more information consult the documentation of your webserver.5657.. _App Engine: http://code.google.com/appengine/