Uable to get around 403 Forbidden Error with FLASK app and mod_wsgi

Viewed 2093

Following tutorial after tutorial and trying a million different configurations, I still am unable to get my flask app to run under mod_wsgi:

My WSGI Script

#!/usr/bin/python
import sys
import logging
import site

logging.basicConfig(stream=sys.stderr)
site.addsitedir('/server/FLASKENV/lib/python3.9/site-packages/')
sys.path.insert(0,"/server/FLASKAPPS/PPSPortal/restapi/")
from main.py import app as application
application.secret_key="REDACTED"

Apache 2 Config:

VirtualHost *:80>
    ServerName myserver.com
    ServerAdmin me@myserver.com
    WSGIScriptAlias / /server/FLASKWSGI/ppsportal.wsgi
    WSGIDaemonProcess ppsrestapi user=www-data group=www-data threads=5 python-home=/server/FLASKENV
    <Directory /server/FLASKAPPS/PPSPortal/restapi>
            Options FollowSymLinks
            AllowOverride None
            Require all granted
    </Directory>
    ErrorLog /server/FLASKAPPS/PPSPortal/restapi/logs/error.log
    LogLevel warn
    CustomLog /server/FLASKAPPS/PPSPortal/restapi/logs/access.log combined
</VirtualHost>

The entire directory for which these apps exists are owned my www-data:www-data and the error I get is 403 Forbidden.

What I am getting in the error.log:

[Sat Aug 14 09:22:57.441200 2021] [authz_core:error] [pid 24121:tid 140166979081984] [client 192.168.0.15:41200] AH01630: client denied by server configuration: /server/FLASKWSGI/ppsportal.wsgi

1 Answers

It sounds like Apache doesn't have access to the object in question. Make sure you have an account set up for this specific reason and give the files access this account. Then use chown to set the access to these files for that user.

In a development environment that can be for example the Apache account. chown -R wwwrun:www /home/user1/Develop/

Or you could give everyone access, but I wouldn't recommend this. chmod 777 -R /home/user1/Develop/

If that doesn't work you may need to manually allow access to the wsgi files in your apache config.

It should look something like this.

WSGIDaemonProcess flask_dbadmin user=wwwrun group=www threads=5
<VirtualHost *:80>

   ........

   <Directory /home/user1/Develop/ >
       Order allow,deny
       Allow from all
    </Directory>

   <Files flask_dbadmin.wsgi>
       Order allow,deny
       Allow from all
   </Files>
</VirtualHost>

-credits : @eandersson

NOTE: Unfortunately I don't have enough reputation to vote this problem as a duplicate.

Related