Deploying Flask

Heroku

to be Done

EECS servers

Apache (on our EECS servers) has been configured to deploy Flask via mod-wsgi. WSGI (Web Server Gateway Interface) is an interface between web servers and web apps for python. Mod_wsgi is an Apache HTTP server mod that enables Apache to serve Flask applications.

1. Flask development

Suppose you have a flask development ~account/www/flask/hello.py.

# hello.py
from flask import Flask

app = Flask(__name__)


@app.route('/')
def hello_world():
    return 'Hello World!'


if __name__ == '__main__':
    app.run()

The folder can be any name (does not have to be flask) anywhere in your www directory. The main app can be any name as well (does not have to be hello.py).

2. Disable directory indexing

For better security, place a .htaccess file in /eecs/home/account/www/flask/.

# Disable directory browsing
Options -Indexes

The above line in .htaccess will remove directory indexing and make the server respond with a 403 forbidden message.

3. wsgi-scripts folder

  • Create a folder ~account/www/wsgi-scripts.
  • Then create a myhello.wsgi in that folder
import sys
sys.path.append('/eecs/home/www/flask')
from hello import app as application

Now visit https://www.eecs.yorku.ca/~account/wsgi-scripts/myhello.wsgi to get

Hello World.

Example

https://www.eecs.yorku.ca/~jonathan/wsgi-scripts/age.wsgi/