2

In my previous question, I asked how to make mod_wsgi use a specific Python version. Following the answer from that question, I created a Python 3.9 virtual environment and made WSGI use it. However, now my Flask app is not running at all - I just get the 404 page configured for the rest of my site. I get no errors when restarting Apache2 and the Apache error log is empty when I visit the site. I think the error must be due to my virtual environment, as I have created previous test Flask apps before using the same config style.

My virtual environment is located in path/to/my/app/venv/.

path/to/my/app/runner.wsgi:

import sys

# Make something appear in error log if the WSGI is run at all
raise ValueError()

PROJECT_DIR = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, PROJECT_DIR)

from my_app import app as application

Part of /etc/apache2/sites-available/000-default-le-ssl.conf:

WSGIDaemonProcess myapp user=www-data group=www-data threads=4 python-home=/path/to/my/app/venv/
WSGIScriptAlias /my-app/ path/to/my/app/runner.wsgi

/etc/apache2/mods-available/wsgi.load

LoadModule wsgi_module "/path/to/my/app/venv/lib/python3.9/site-packages/mod_wsgi/server/mod_wsgi-py39.cpython-39-x86_64-linux-gnu.so"
WSGIPythonHome "path/to/my/app/venv"

OS: Ubuntu 18.04.5 LTS

ThatCoolCoder
  • 181
  • 1
  • 6

2 Answers2

1

Ok, I found the problem. It was really stupid. Basically, I was writing /var/www/my_app instead of /var/www/my-app in /etc/apache2/sites-available/000-default-le-ssl.conf. I fixed the paths, disabled the site, enabled the site, reloaded Apache and now it works. I'm curious as to why Apache doesn't at least give a warning if it can't access the WSGI file.

ThatCoolCoder
  • 181
  • 1
  • 6
0
  • Which user is running Apache?

  • Can that user actually access your WSGI application? Check this by running ls -la on the path and all its components, or by using namei (namei /path/....)

  • Is SELinux in enforcing mode? If so, check audit logs. audit2why can be useful (you may have to install some packages).

A. Darwin
  • 427
  • 1
  • 4
  • Apache is being run by `root` (1 instance) and `www-data` (multiple instances). I believe they can access the directory (which is in `var/www`), as I tried some tests I found online and the whole directory has permissions `0777` anyway. I don't think I'm using SELinux because all of the SELinux commands are not found. – ThatCoolCoder Jul 27 '21 at 04:32