Search code examples
python-3.xapacheflaskraspberry-pi3mod-wsgi

how to Running Flask with Apache2 and Mod-WSGI


I'm trying to Running Flask with Apache2 and Mod-WSGI in my raspberry I got The requested URL that was not found on this server I try to edit 000-default.conf but app won't with Mod-WSGI. I used python 3

can someone let me know what is the problem?

thank you this is my status from apache2:

enter image description here

this is app.wsgi :

#!/usr/bin/python3
import sys
sys.path.insert(0, '/var/www/html/prox')
from init import app as application

this is 000-default.conf

Listen 5000

<VirtualHost *:5000>

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/prox

    LogLevel debug

    WSGIScriptAlias / /var/www/html/prox/app.wsgi
    WSGIDaemonProcess prox processes=5 threads=1 user=pi group=pi display-name=%{GROUP}
    WSGIProcessGroup prox
    WSGIApplicationGroup %{GLOBAL}
    WSGIPassAuthorization On
    WSGIChunkedRequest On
    ErrorLog ${APACHE_LOG_DIR}/error-5000.log
    CustomLog ${APACHE_LOG_DIR}/access-5000.log combined

    <Directory /var/www/html/prox>
        <IfVersion >= 2.4>
            Require all granted
        </IfVersion>
        <IfVersion < 2.4>
            Order allow,deny
            Allow from all
        </IfVersion>
    </Directory>

this the app: named app.py

from flask import Flask, render_template

app = Flask(__name__)
@app.route('/')
def home_page():
    return render_template('index.html')

app.debug = True
if __name__ == '__main__'
    app.run()

this is journalctl -xe : enter image description here

I got this error

enter image description here


Solution

  • Try starting the flask app itself on your apache server, for example.

    // Find your flask app
    export FLASK_APP=<YOUR_FILE>
    
    // Host it on your local network
    flask run --host=0.0.0.0
    

    This will start the server, makes sure you are in the virtual environment and directory your flask app is stored in.