Django Rollout到Apache2服务器WSGI脚本加载失败

时间:2017-10-17 13:17:09

标签: python django apache mod-wsgi

这是我第一次尝试部署Django项目。我在Pi3上使用Raspbian。该项目使用内置的Django测试服务器。项目根目录(manage.py文件所在的位置)是:

/datadisk/powermon/power

virtualenv位于:

/datadisk/powermon/pja

Django settings.py文件位于:

/datadisk/powermon/power/power

我已将以下行添加到/etc/apache2/sites-enabled/000-default.conf

WSGIDaemonProcess power python-home=/datadisk/powermon/pja
WSGIProcessGroup power
WSGIScriptAlias /power /datadisk/powermon/power/power/wsgi.py
WSGIApplicationGroup $(GLOBAL)
<Directory /datadisk/powermon/power/power>
    <Files wsgi.py>
        require all granted
    </Files>
</Directory>

Apache在更改后重新启动。

WSGI文件是Django创建的默认文件。

import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "power.settings")
application = get_wsgi_application()

当浏览器尝试访问该网站时,它会收到500内部服务器错误

Apache在/var/log/apache2/error.log

中报告以下内容
[Tue Oct 17 13:05:25.006487 2017] [wsgi:error] [pid 764] [remote 192.168.0.106:0] mod_wsgi (pid=764): Target WSGI script '/datadisk/powermon/power/power/wsgi.py' cannot be loaded as Python module.
[Tue Oct 17 13:05:25.007679 2017] [wsgi:error] [pid 764] [remote 192.168.0.106:0] mod_wsgi (pid=764): Exception occurred processing WSGI script '/datadisk/powermon/power/power/wsgi.py'.
[Tue Oct 17 13:05:25.008344 2017] [wsgi:error] [pid 764] [remote 192.168.0.106:0] Traceback (most recent call last):
[Tue Oct 17 13:05:25.009152 2017] [wsgi:error] [pid 764] [remote 192.168.0.106:0]   File "/datadisk/powermon/power/power/wsgi.py", line 24, in <module>
[Tue Oct 17 13:05:25.009311 2017] [wsgi:error] [pid 764] [remote 192.168.0.106:0]     application = get_wsgi_application()
[Tue Oct 17 13:05:25.009905 2017] [wsgi:error] [pid 764] [remote 192.168.0.106:0]   File "/datadisk/powermon/pja/lib/python3.4/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Tue Oct 17 13:05:25.010040 2017] [wsgi:error] [pid 764] [remote 192.168.0.106:0]     django.setup(set_prefix=False)
[Tue Oct 17 13:05:25.010583 2017] [wsgi:error] [pid 764] [remote 192.168.0.106:0]   File "/datadisk/powermon/pja/lib/python3.4/site-packages/django/__init__.py", line 22, in setup
[Tue Oct 17 13:05:25.010719 2017] [wsgi:error] [pid 764] [remote 192.168.0.106:0]     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Tue Oct 17 13:05:25.011321 2017] [wsgi:error] [pid 764] [remote 192.168.0.106:0]   File "/datadisk/powermon/pja/lib/python3.4/site-packages/django/conf/__init__.py", line 56, in __getattr__
[Tue Oct 17 13:05:25.011461 2017] [wsgi:error] [pid 764] [remote 192.168.0.106:0]     self._setup(name)
[Tue Oct 17 13:05:25.011991 2017] [wsgi:error] [pid 764] [remote 192.168.0.106:0]   File "/datadisk/powermon/pja/lib/python3.4/site-packages/django/conf/__init__.py", line 41, in _setup
[Tue Oct 17 13:05:25.012122 2017] [wsgi:error] [pid 764] [remote 192.168.0.106:0]     self._wrapped = Settings(settings_module)
[Tue Oct 17 13:05:25.012677 2017] [wsgi:error] [pid 764] [remote 192.168.0.106:0]   File "/datadisk/powermon/pja/lib/python3.4/site-packages/django/conf/__init__.py", line 110, in __init__
[Tue Oct 17 13:05:25.012807 2017] [wsgi:error] [pid 764] [remote 192.168.0.106:0]     mod = importlib.import_module(self.SETTINGS_MODULE)
[Tue Oct 17 13:05:25.013346 2017] [wsgi:error] [pid 764] [remote 192.168.0.106:0]   File "/datadisk/powermon/pja/lib/python3.4/importlib/__init__.py", line 109, in import_module
[Tue Oct 17 13:05:25.013482 2017] [wsgi:error] [pid 764] [remote 192.168.0.106:0]     return _bootstrap._gcd_import(name[level:], package, level)
[Tue Oct 17 13:05:25.014166 2017] [wsgi:error] [pid 764] [remote 192.168.0.106:0]   File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
[Tue Oct 17 13:05:25.014602 2017] [wsgi:error] [pid 764] [remote 192.168.0.106:0]   File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
[Tue Oct 17 13:05:25.015010 2017] [wsgi:error] [pid 764] [remote 192.168.0.106:0]   File "<frozen importlib._bootstrap>", line 2212, in _find_and_load_unlocked
[Tue Oct 17 13:05:25.015412 2017] [wsgi:error] [pid 764] [remote 192.168.0.106:0]   File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
[Tue Oct 17 13:05:25.015811 2017] [wsgi:error] [pid 764] [remote 192.168.0.106:0]   File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
[Tue Oct 17 13:05:25.016194 2017] [wsgi:error] [pid 764] [remote 192.168.0.106:0]   File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
[Tue Oct 17 13:05:25.016577 2017] [wsgi:error] [pid 764] [remote 192.168.0.106:0]   File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked
[Tue Oct 17 13:05:25.017090 2017] [wsgi:error] [pid 764] [remote 192.168.0.106:0] ImportError: No module named 'power'

我所做的阅读表明,WSGI和Python的版本可能不兼容。我使用python-3.4.2构建项目。我已经卸载了用于python-2.7的WSGI并安装了python-3的版本。当Apache2重新启动时,error.log中会出现以下行:

[Tue Oct 17 13:11:09.523741 2017] [mpm_prefork:notice] [pid 2118] AH00163: Apache/2.4.10 (Raspbian) mod_wsgi/4.3.0 Python/3.4.2 configured -- resuming normal operations

这一行是否意味着已经设置了Python 3.4.2的WSGI?如果是这样,为什么它出现在error.log文件中?如何找到安装了哪个版本的WSGI?是否有其他原因导致这个问题?

谢谢。

0 个答案:

没有答案