Kör en Flask-applikation i Apache på linux med hjälp av wsgi-modulen.
Ladda ner wsgi:
1. app.py:
2. yourwsgi.wsgi:
3. Lägg till en Virtual Host https://dbwebb.se/kurser/linux/kmom02
Innehåll i yourconfigfile.conf:
4. Följ linux kursens kmom02 för att lägga till i /etc/hosts och "enabla" din VH.
Ladda ner wsgi:
- Kod: Markera allt
# För python3 varianten
$ sudo apt-get -y install libapache2-mod-wsgi-py3
1. app.py:
- Kod: Markera allt
#!/usr/bin/env python3
from flask import Flask
app = Flask(__name__)
@app.route("/")
def main():
""" main route """
return "Det funkar!"
if __name__ == "__main__":
app.run(debug=True)
2. yourwsgi.wsgi:
- Kod: Markera allt
import sys
if sys.version_info[0]<3: # require python3
raise Exception("Python3 required! Current (wrong) version: '%s'" % sys.version_info)
sys.path.append('/Path/to/app.py/directory')
from app import app as application
3. Lägg till en Virtual Host https://dbwebb.se/kurser/linux/kmom02
Innehåll i yourconfigfile.conf:
- Kod: Markera allt
<VirtualHost *:80>
ServerName yourServerName
WSGIDaemonProcess yourwsgi user=yourUser group=yourUser threads=5
WSGIScriptAlias / /Path/to/your/yourwsgi.wsgi
ErrorLog /path/to/errorlog/error.log
CustomLog /path/to/accesslog/access.log combined
<Directory /Path/to/your/yourwsgi.wsgi-directory>
WSGIProcessGroup yourwsgi
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
4. Följ linux kursens kmom02 för att lägga till i /etc/hosts och "enabla" din VH.
When in doubt, use brute force.