Skip to content

Instantly share code, notes, and snippets.

@ludwig
Last active August 29, 2015 14:00
Show Gist options
  • Save ludwig/11363777 to your computer and use it in GitHub Desktop.
Save ludwig/11363777 to your computer and use it in GitHub Desktop.
Flask app on WebFaction
# File /home/ludwig/webapps/flask/apache2/conf/httpd.conf
ServerRoot "/home/ludwig/webapps/flask/apache2"
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule wsgi_module modules/mod_wsgi.so
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog /home/ludwig/logs/user/access_flask.log combined
DirectoryIndex index.py
DocumentRoot /home/ludwig/webapps/flask/htdocs
ErrorLog /home/ludwig/logs/user/error_flask.log
KeepAlive Off
Listen 23908
MaxSpareThreads 3
MinSpareThreads 1
ServerLimit 1
SetEnvIf X-Forwarded-SSL on HTTPS=1
ThreadsPerChild 5
# XXX: changed 'python-path' in this line
WSGIDaemonProcess flask processes=5 python-path=/home/ludwig/webapps/flask/htdocs threads=1
WSGIProcessGroup flask
WSGIRestrictEmbedded On
WSGILazyInitialization On
# XXX: added these two lines
WSGIPythonPath /home/ludwig/webapps/flask/htdocs/
WSGIScriptAlias / /home/ludwig/webapps/flask/htdocs/index.py
<Directory /home/ludwig/webapps/flask/htdocs>
AddHandler wsgi-script .py
# XXX: Added these three lines
RewriteEngine on
RewriteBase /
WSGIScriptReloading On
</Directory>
# File /home/ludwig/webapps/flask/htdocs/index.py
from myapp import app as application
#!/usr/bin/env python3.3
# File /home/ludwig/webapps/flask/htdocs/myapp.py
# See http://flask.pocoo.org/snippets/65/
from flask import Flask
app = Flask(__name__)
class WebFactionMiddleware(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
environ['SCRIPT_NAME'] = '/flask'
return self.app(environ, start_response)
app.wsgi_app = WebFactionMiddleware(app.wsgi_app)
@app.route("/")
def hello():
return "Hello World from Flask!"
if __name__ == "__main__":
app.run()
# make sure python3.3 can find Flask module
[ludwig@web178 ~]$ easy_install-3.3 pip
[ludwig@web178 ~]$ pip3.3 install flask
# after changing httpd.conf
[ludwig@web178 ~]$ ~/webapps/flask/apache2/bin/restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment