目标wsgi脚本无法正确加载

时间:2015-03-29 20:47:44

标签: python django apache2 mod-wsgi wsgi

我正在尝试使用mod_wsgi和apache2部署Django Web服务器,我收到内部服务器错误。

[Sun Mar 29 16:13:00.382493 2015] [mpm_event:notice] [pid 1194:tid 139655348275072] AH00489: Apache/2.4.7 (Ubuntu) mod_wsgi/3.4 Python/2.7.6 configured -- resuming normal operations
[Sun Mar 29 16:13:00.382514 2015] [core:notice] [pid 1194:tid 139655348275072] AH00094: Command line: '/usr/sbin/apache2'
[Sun Mar 29 20:13:03.159156 2015] [:error] [pid 26383:tid 139655211136768] [remote 71.88.97.195:25099] mod_wsgi (pid=26383): Target WSGI script '/var/www/mbusuite/mbusuite/wsgi.py' cannot be loaded as Python module.
[Sun Mar 29 20:13:03.159199 2015] [:error] [pid 26383:tid 139655211136768] [remote 71.88.97.195:25099] mod_wsgi (pid=26383): Exception occurred processing WSGI script '/var/www/mbusuite/mbusuite/wsgi.py'.
[Sun Mar 29 20:13:03.159221 2015] [:error] [pid 26383:tid 139655211136768] [remote 71.88.97.195:25099] Traceback (most recent call last):
[Sun Mar 29 20:13:03.159258 2015] [:error] [pid 26383:tid 139655211136768] [remote 71.88.97.195:25099]   File "/var/www/mbusuite/mbusuite/wsgi.py", line 16, in <module>
[Sun Mar 29 20:13:03.159317 2015] [:error] [pid 26383:tid 139655211136768] [remote 71.88.97.195:25099]     application = get_wsgi_application()
[Sun Mar 29 20:13:03.159329 2015] [:error] [pid 26383:tid 139655211136768] [remote 71.88.97.195:25099]   File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Sun Mar 29 20:13:03.159368 2015] [:error] [pid 26383:tid 139655211136768] [remote 71.88.97.195:25099]     django.setup()
[Sun Mar 29 20:13:03.159379 2015] [:error] [pid 26383:tid 139655211136768] [remote 71.88.97.195:25099]   File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
[Sun Mar 29 20:13:03.159415 2015] [:error] [pid 26383:tid 139655211136768] [remote 71.88.97.195:25099]     apps.populate(settings.INSTALLED_APPS)
[Sun Mar 29 20:13:03.159427 2015] [:error] [pid 26383:tid 139655211136768] [remote 71.88.97.195:25099]   File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 85, in populate
[Sun Mar 29 20:13:03.159563 2015] [:error] [pid 26383:tid 139655211136768] [remote 71.88.97.195:25099]     app_config = AppConfig.create(entry)
[Sun Mar 29 20:13:03.159575 2015] [:error] [pid 26383:tid 139655211136768] [remote 71.88.97.195:25099]   File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 87, in create
[Sun Mar 29 20:13:03.159654 2015] [:error] [pid 26383:tid 139655211136768] [remote 71.88.97.195:25099]     module = import_module(entry)
[Sun Mar 29 20:13:03.159665 2015] [:error] [pid 26383:tid 139655211136768] [remote 71.88.97.195:25099]   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
[Sun Mar 29 20:13:03.159708 2015] [:error] [pid 26383:tid 139655211136768] [remote 71.88.97.195:25099]     __import__(name)
[Sun Mar 29 20:13:03.159739 2015] [:error] [pid 26383:tid 139655211136768] [remote 71.88.97.195:25099] ImportError: No module named storage

我的apache配置文件是:

<VirtualHost *:80>
    ServerName mbusuite.duckdns.org
    WSGIDaemonProcess mbusuite.duckdns.org python-path=/var/www/mbusuite:/usr/local/lib/python2.7/site-packages
    WSGIProcessGroup mbusuite.duckdns.org
    WSGIScriptAlias / /var/www/mbusuite/mbusuite/wsgi.py process-group=mbusuite.duckdns.org
    ServerAdmin mbu@wpi.edu

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    #<Directory /var/www/mbusuite/static>
    #       Require all granted
    #</Directory>
    #<Directory /var/www/mbusuite/core>
    #       Require all granted
    #</Directory>
    #<Directory /var/www/mbusuite/templates>
    #       Require all granted
    #</Directory>
    <Directory /var/www/mbusuite/>
            <Files wsgi.py>
                    Require all granted
            </Files>
    </Directory>
</VirtualHost>

wsgi.py是

"""
WSGI config for mbusuite project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/
"""

import os
import sys
os.environ["DJANGO_SETTINGS_MODULE"] = "mbusuite.settings"

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

我不太确定这是权限问题还是配置问题。任何帮助都会很棒。

1 个答案:

答案 0 :(得分:0)

我认为您无法在WSGIScriptAlias指令上指定进程组,并且您的python-path指令必须与您在wsgi.py文件中的指令相匹配(即DJANGO_SETTINGS_MODULE必须可从python路径导入指定)。您不应该授予wsgi.py文件的权限(理想情况下,您不会在/ var / www下使用源代码,因为这通常是Apache的docroot区域 - 并且您不希望任何服务原始源的可能性)。类似的东西:

<VirtualHost *:80>
    ServerName mbusuite.duckdns.org
    WSGIScriptAlias / /var/www/mbusuite/mbusuite/wsgi.py 
    WSGIProcessGroup mbusuite.duckdns.org
    WSGIDaemonProcess mbusuite.duckdns.org \
        python-path=/var/www:/usr/local/lib/python2.7/site-packages

    ServerAdmin mbu@wpi.edu

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

应该使用您当前的wsgi.py(您可能还需要声明docroot - 您可以使用它来提供例如favicon.ico个文件; - )