Home > Mobile >  403 forbidden using a flask app with WSGI and Apache2.4
403 forbidden using a flask app with WSGI and Apache2.4

Time:01-06

I'm trying to run a dash app on our website in a sub-directory. I'm getting a 403 forbidden when trying to access to website. In the /etc/httpd/logs/ssl_error_logs i get the error:

[Tue Jan 03 13:53:42.973046 2023] [autoindex:error] [pid 50576] [client 134.94.71.5:60550] AH01276: Cannot serve directory /var/www/Typesetter/appname/: No matching DirectoryIndex (index.html,index.php,index.php) found, and server-generated directory index forbidden by Options directive

I think i might have something wrong with either the permissions or the virtualhost setup. But i can't figure out what is going wrong.

I want to run the dashboard on: our-group.our-uni.com/appname

The server is running on centos7.

I got a data folder with biochemical information to provide to the users in /var/www/html/appname/data/ from which i can download the data if i go to our-group.our-uni.com/appname/data/datapoint1.pt.

Since this works and i can also put a index.html/index.php page there without issues, i think my virtualhost setup pointing to WSGI is incorrect?

The error says cannot serve directory /var/www/Typesetter/appname/, but this directory is a symbolic link to /var/www/html/appname/.

The virtualhost file appname.conf located in /etc/httpd/conf.d/:

<VirtualHost *:80>
        ServerName our-group.our-uni.com

        DocumentRoot /var/www/html/appname

        Errorlog /var/www/html/appname/appname-error.log

        Alias /topenzyme /var/www/html/topenzmye

        WSGIDaemonProcess appname user=apache group=apache threads=5 python-path=/var/www/html/appname/appname-env
        WSGIScriptAlias /appname /var/www/html/appname/testapp.wsgi

        <Directory /var/www/html/appname>
            WSGIProcessGroup appname
            WSGIApplicationGroup %{GLOBAL}
            Options Indexes FollowSymLinks ExecCGI
            Require all granted
        </Directory>
</VirtualHost>

I also tried changing to <Directory /var/www/typesetter/appname>, but this also did not work.

The contents of testapp.wsgi in /var/www/html/appname/:

import sys, os
sys.path.insert(0, '/var/www/html/appname')
from testapp import app as application

The contents of testapp.py in /var/www/html/appname/:

from flask import Flask
app = Flask(__name__)

@app.route('/topenzyme/')
def main():
    return 'Hello world'

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

Permission setup:

-rwxr-xr-x.  1 apache    apache      148 Jan  3 13:37 testapp.py
-rwxr-xr-x.  1 apache    apache      100 Jan  3 13:38 testapp.wsgi

I also tried 777, but from what i've read 755 permissions should be sufficient?

If i do httpd -M i get wsgi_module (shared). The wsgi module should be available.

I tried various virtualhost configs from other posts with similar issues.

I'm really unsure why this is not working.

Is there anything wrong with my configuration settings or could it be something else?

CodePudding user response:

Found out the issue. I was miss-configuring my Apache setup.

As we are already hosting a website on the domain, i should not have tried to setup a virtualhost for the sub-directory. From what i understand now this only works for setting up (sub)domains. With this structure of setting it up the appname.conf file gets added the already existing virtualhost config.

Instead the /etc/httpd/conf.d/appname.conf is now:

WSGIDaemonProcess appname user=apache group=apache threads=5 python-path=/var/www/html/appname/appnameenv
WSGIProcessGroup appname 
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias /appname /var/www/html/appname/testapp.wsgi

<Directory /var/www/html/appname>
        Options FollowSymLinks
        AllowOverride  All
        Require all granted
        allow from all
</Directory>

This corrently links the wsgi application to my sub-directory location i wanted (our-group.our-uni.com/appname)

  • Related