Score:2

Why is Apache2 not finding my WSGI app?

ru flag

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

Score:1
ru flag

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.

Score:0
my flag
  • 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).

ThatCoolCoder avatar
ru flag
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.

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.