大网数据广告活动
服务器运维问答

Why is Apache2 not finding my WSGI app?

· 52CE 我爱测

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 runni…

问题原文

原帖链接 · ThatCoolCoder · CC BY-SA 4.0

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 · CC BY-SA 4.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-07-25)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。