处理WSGI脚本时发生异常

时间:2013-09-24 15:01:26

标签: django apache mod-wsgi

我正在尝试安装一个开源的Django应用程序(OSQA),但是我收到了这个错误:

[Tue Sep 24 10:37:09 2013] [error] mod_wsgi (pid=82486): Exception occurred processing WSGI script '/home/fuiba/webapps/osqa/osqa.wsgi'.
[Tue Sep 24 10:37:09 2013] [error] Traceback (most recent call last):
[Tue Sep 24 10:37:09 2013] [error]   File "/home/fuiba/webapps/osqa/lib/python2.7/django/core/handlers/wsgi.py", line 232, in __call__
[Tue Sep 24 10:37:09 2013] [error]     self.load_middleware()
[Tue Sep 24 10:37:09 2013] [error]   File "/home/fuiba/webapps/osqa/lib/python2.7/django/core/handlers/base.py", line 42, in load_middleware
[Tue Sep 24 10:37:09 2013] [error]     raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))
[Tue Sep 24 10:37:09 2013] [error] ImproperlyConfigured: Error importing middleware django.contrib.sessions.middleware: "No module named base"

这是我的osqa.wsgi

import os
import sys
sys.path.append('/home/fuiba/webapps/osqa/osqa')

from django.core.handlers.wsgi import WSGIHandler
os.environ['DJANGO_SETTINGS_MODULE'] = 'osqa.settings'
application = WSGIHandler()

httpd.conf 中我有WSGIScriptAlias

WSGISocketPrefix ${APACHE_RUN_DIR}
WSGIPythonPath /home/fuiba/webapps/osqa:/home/fuiba/webapps/osqa/lib/python2.7  
WSGIScriptAlias / /home/fuiba/webapps/osqa/osqa.wsgi

在apache2文件夹(/home/fuiba/webapps/osqa/apache2)中,我收到一个名字很奇怪的文件: $ {APACHE_RUN_DIR} .47892.0.1.sock

这是什么?

感谢任何帮助。
谢谢!

1 个答案:

答案 0 :(得分:1)

尝试重新配置WSGI,例如通过定义项目的一般路径和apache

osqa.wsgi:

import os, sys

#path to directory of the .wgsi file ('[directory]/')
wsgi_dir = os.path.abspath(os.path.dirname(__file__))

# path to project root directory (osqa '/')
project_dir = os.path.dirname(wsgi_dir)

# add project  directory to system's Path
sys.path.append(project_dir)
sys.path.append('/home/fuiba/webapps/osqa/osqa')


os.environ['PYTHON_EGG_CACHE'] = '/home/fuiba/webapps/osqa/osqa/.python-egg'
#add the setting.py file to your system's path
project_settings = os.path.join(project_dir,'settings')

#explicitly define the DJANGO_SETTINGS_MODULE
os.environ['DJANGO_SETTINGS_MODULE'] ='osqa.settings'

import django.core.handlers.wsgi
application =django.core.handlers.wsgi.WSGIHandler()

在http.conf中:

只保留虚拟主机中的WSGIScriptAlias,该路径将在wsgi文件中定义

WSGIScriptAlias / /home/fuiba/webapps/osqa/osqa.wsgi
WSGIScriptReloading On
WSGIProcessGroup domain.com
WSGIDaemonProcess domain.com user=user processes=10 threads=1 maximum-requests=500

如果也安装了libapache2_mod_wsgi,它应该可以工作