Last active
August 29, 2015 14:07
-
-
Save danihodovic/badd29ca65bc20d50e13 to your computer and use it in GitHub Desktop.
Flask Deployment Simple Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# File /var/www/wsgi_app/app.py | |
# The Flask application | |
#!/usr/bin/env python | |
from flask import Flask | |
app = Flask(__name__) | |
@app.route('/') | |
def index(): | |
return ('Hello, world') | |
# Not used in apache, so it doesn't matter | |
if __name__ == '__main__': | |
app.run(host=None, port=None, debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Instructions: | |
1. Added the three files below to the right places. | |
2. Disable the default site, otherwise the WSGI app won't be shown for some reason. | |
This one took me a LONG time to figure out. | |
# The default file under Debian/Ubuntu | |
>sudo a2dissite 000-default.conf | |
3. Enable the WSGI project. | |
>sudo a2ensite wsgi_example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# File /var/www/wsgi_app/wsgi.py | |
# The WSGI file used by Apache to run your Flask app | |
import logging, sys | |
# Logging, in case something goes wrong. Found in /var/log/apache2/error.log, specificed in the conf file above. | |
# /var/log/apache2 is the default global variable. | |
logging.basicConfig(stream=sys.stderr) | |
from app import app as application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# File: /etc/apache2/sites-available/wsgi_example.conf | |
# The Apache configuration | |
# The apache config file found in /etc/apache2/sites-available/ in Debian/Ubuntu | |
# Note that this is in sites-available not sites-enabled. Sites-enabled only contains a symlink to sites-available and may be enabled/disabled with a2dissite | |
<VirtualHost *:80> | |
# Where the project is served and the physical wsgi file location | |
WSGIScriptAlias / /var/www/wsgi_app/wsgi.py | |
# The daemon process and the options https://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIDaemonProcess | |
# Here I've added /var/www/wsgi_app to the python path so wsgi can | |
# import it when running. Otherwise you could do it in the wsgi.py file like so | |
# import sys | |
# sys.path.insert(0, '/path/to/the/application') | |
WSGIDaemonProcess example python-path=/var/www/wsgi_app/ threads=25 processes=2 | |
# The name of the process group (?) | |
WSGIProcessGroup example | |
<Directory /var/www/wsgi_app> | |
Order deny,allow | |
Allow from all | |
</Directory> | |
# Should add a static directory here | |
# The logs are found in /var/log/apache2 under Debian/Ubuntu | |
ErrorLog ${APACHE_LOG_DIR}/error.log | |
LogLevel warn | |
CustomLog ${APACHE_LOG_DIR}/access.log combined | |
</VirtualHost> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment