[PYTHON] Run Apache2 + WSGI + Flask

environment

Setting

setting file

/var/www/html/flask
- Hello.py
- test.wsgi
/etc/apache2/sites-available
- wsgi.conf

First of all, the script itself.

Hello.py


from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
    return 'Hello'

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

Then create a WSGI file.

test.wsgi


import sys, site

sys.path.insert(0, '/var/www/html/flask')
from Hello import app as application

Settings on the Apache side.

# wsgi.conf
<VirtualHost *:80>
serverName (IP address or domain name of the contracted server)

WSGIDaemonProcess test user=(User name to execute Python) group=(Group of users) threads=5
WSGIScriptAlias / /var/www/html/flask/test.wsgi

<Directory /var/www/html/flask>

WSGIProcessGroup test 
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On

Require all granted

</Directory>
</VirtualHost>

Reboot the server

Enable wsgi.conf.

$ sudo a2ensite wsgi

And restart Apache.

$ sudo service apache2 restart

Now when you visit the site you should see "Hello".

Referenced

Recommended Posts

Run Apache2 + WSGI + Flask
Until it works with virtualenv + flask + apache + wsgi
Run the flask app on Cloud9 and Apache Httpd
Touch Flask + run with Heroku
Preparing to run Flask on EC2
Use Flask to run external files
flask
flask
[Python] Run Flask on Google App Engine
speed difference between wsgi, Bottle and Flask
Run python wsgi server on NGINX Unit