【发布时间】:2021-10-07 16:24:08
【问题描述】:
关于这个主题的帖子大约有一百个,但似乎没有一个有太多的押韵或理由。
我的配置:
-
尝试通过 Podman 用 Apache + mod_wsgi (4.6.4) + Django 构建容器,没有 virtualenv。
-
通过 CentOS 软件包 repo 二进制文件安装已编译的库。 Python 3.6 通过 CentOS repo 二进制文件。
-
通过 pip 将纯 python 库安装到 --user (/home/user/.local)
-
项目文件夹在 /home/apache 中,不需要任何静态内容,我会将所有内容推送到 CDN。
-
the docs 的测试文件示例运行良好。
-
迁移和迁移后信号工作正常。
-
开发服务器在当前配置下工作正常。
-
我指定 Django 和 base-Python 相关的唯一环境变量是 DJANGO_SETTINGS_MODULE,它已正确设置为我的基本设置文件。
-
Apache 配置,直接来自 Django 3.2 文档:
WSGIPythonPath /home/apache
<VirtualHost *:8080>
ServerName localhost
WSGIScriptAlias / /home/apache/base/wsgi.py
<Directory /home/apache/base>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
结果:
[ 09:20:57.757787 2021] [wsgi:error] [pid 5:tid 140007184484096] Traceback (most recent call last):
[ 09:20:57.758173 2021] [wsgi:error] [pid 5:tid 140007184484096] File "/home/apache/base/wsgi.py", line 16, in <module>
[ 09:20:57.758542 2021] [wsgi:error] [pid 5:tid 140007184484096] application = get_wsgi_application()
[ 09:20:57.758740 2021] [wsgi:error] [pid 5:tid 140007184484096] File "/home/apache/.local/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[ 09:20:57.759100 2021] [wsgi:error] [pid 5:tid 140007184484096] django.setup(set_prefix=False)
[ 09:20:57.759335 2021] [wsgi:error] [pid 5:tid 140007184484096] File "/home/apache/.local/lib/python3.6/site-packages/django/__init__.py", line 19, in setup
[ 09:20:57.759539 2021] [wsgi:error] [pid 5:tid 140007184484096] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[ 09:20:57.759844 2021] [wsgi:error] [pid 5:tid 140007184484096] File "/home/apache/.local/lib/python3.6/site-packages/django/conf/__init__.py", line 82, in __getattr__
[ 09:20:57.760108 2021] [wsgi:error] [pid 5:tid 140007184484096] self._setup(name)
[ 09:20:57.760483 2021] [wsgi:error] [pid 5:tid 140007184484096] File "/home/apache/.local/lib/python3.6/site-packages/django/conf/__init__.py", line 69, in _setup
[ 09:20:57.760772 2021] [wsgi:error] [pid 5:tid 140007184484096] self._wrapped = Settings(settings_module)
[ 09:20:57.761133 2021] [wsgi:error] [pid 5:tid 140007184484096] File "/home/apache/.local/lib/python3.6/site-packages/django/conf/__init__.py", line 170, in __init__
[ 09:20:57.762015 2021] [wsgi:error] [pid 5:tid 140007184484096] mod = importlib.import_module(self.SETTINGS_MODULE)
[ 09:20:57.762347 2021] [wsgi:error] [pid 5:tid 140007184484096] File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
[ 09:20:57.762636 2021] [wsgi:error] [pid 5:tid 140007184484096] return _bootstrap._gcd_import(name[level:], package, level)
[ 09:20:57.763139 2021] [wsgi:error] [pid 5:tid 140007184484096] File "<frozen importlib._bootstrap>", line 994, in _gcd_import
[ 09:20:57.763347 2021] [wsgi:error] [pid 5:tid 140007184484096] File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[ 09:20:57.763613 2021] [wsgi:error] [pid 5:tid 140007184484096] File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
[ 09:20:57.763895 2021] [wsgi:error] [pid 5:tid 140007184484096] File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[ 09:20:57.764154 2021] [wsgi:error] [pid 5:tid 140007184484096] File "<frozen importlib._bootstrap>", line 994, in _gcd_import
[ 09:20:57.764414 2021] [wsgi:error] [pid 5:tid 140007184484096] File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[ 09:20:57.764702 2021] [wsgi:error] [pid 5:tid 140007184484096] File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
[ 09:20:57.764985 2021] [wsgi:error] [pid 5:tid 140007184484096] File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[ 09:20:57.765289 2021] [wsgi:error] [pid 5:tid 140007184484096] File "<frozen importlib._bootstrap>", line 994, in _gcd_import
[ 09:20:57.765555 2021] [wsgi:error] [pid 5:tid 140007184484096] File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[ 09:20:57.765874 2021] [wsgi:error] [pid 5:tid 140007184484096] File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
[ 09:20:57.766160 2021] [wsgi:error] [pid 5:tid 140007184484096] ModuleNotFoundError: No module named "'base"
10.0.2.100 - - [02/Aug/2021:09:20:57 +0000] "GET / HTTP/1.1" 500 527 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15"
是“base”旁边的那个额外的单引号吗?我想它一定是,而且没有明显的迹象表明它来自哪里。
它不在我能看到的任何 Apache 配置中。也不是在我的网站代码中,在全球 Sublime 中搜索了“base 并且一切对我来说都很好”。
【问题讨论】:
标签: django docker apache mod-wsgi