apache,mod_wsgi,django 1.4上的内部服务器错误

时间:2012-12-28 10:51:15

标签: django apache mod-wsgi virtualenvwrapper

我正在写一个django网站供我的组织内部使用。我正在使用测试驱动的方法来开发this tutorial中提出的网站,因为我认为这是一种很好的做法。我正在使用Ubuntu 12.04,以及来自存储库的apache服务器和mod_wsgi。我的开发是在使用virtualenvwrapper创建的virtualenv中进行的。

我想在尽可能接近生产服务器的条件下测试网站,所以我尝试使用mod_wsgi在笔记本电脑上配置本地apache服务器,这是我以前从未做过的。我已经阅读了mod_wsgidjango docs的相关位,并观看了this video,这解决了我在文件权限方面遇到的问题。但我似乎陷入了演示文稿没有解决的最后障碍 - 我认为因为我使用django 1.4并且它与早期版本有关但我不确定。我承诺使用本地apache服务器而不是django开发服务器,因为该站点需要搜索,我想通过haystack和apache solr,我想在部署之前测试它并解决任何问题。

我的wsgi.py文件只是股票django。修剪文档字符串后,它看起来像这样:

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "fugit.settings")

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)

我的httpd.conf看起来像这样:

WSGIScriptAlias / /var/www/djcode/fugit/fugit/fugit/apache/wsgi.py
WSGIPythonPath /var/www/djcode/fugit/fugit/fugit:/home/garry/.virtualenvs/fugit/lib/python2.7/site-packages


<Directory /var/www/djcode/fugit/fugit/fugit>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>

当我访问localhost时,我收到以下错误。它看起来像PYTHONPATH问题,但我对django文档的理解是上面的httpd.conf中的第二行应该已经解决了。

[Fri Dec 28 10:22:03 2012] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Fri Dec 28 10:22:03 2012] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Fri Dec 28 10:22:03 2012] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
[Fri Dec 28 10:22:05 2012] [error] [client 127.0.0.1] mod_wsgi (pid=3280): Target WSGI script '/var/www/djcode/fugit/fugit/fugit/apache/wsgi.py' cannot be loaded as Python module.
[Fri Dec 28 10:22:05 2012] [error] [client 127.0.0.1] mod_wsgi (pid=3280): Exception occurred processing WSGI script '/var/www/djcode/fugit/fugit/fugit/apache/wsgi.py'.
[Fri Dec 28 10:22:05 2012] [error] [client 127.0.0.1] Traceback (most recent call last):
[Fri Dec 28 10:22:05 2012] [error] [client 127.0.0.1]   File "/var/www/djcode/fugit/fugit/fugit/apache/wsgi.py", line 23, in <module>
[Fri Dec 28 10:22:05 2012] [error] [client 127.0.0.1]     from django.core.wsgi import get_wsgi_application
[Fri Dec 28 10:22:05 2012] [error] [client 127.0.0.1] ImportError: No module named django.core.wsgi
[Fri Dec 28 10:22:08 2012] [error] [client 127.0.0.1] mod_wsgi (pid=3279): Target WSGI script '/var/www/djcode/fugit/fugit/fugit/apache/wsgi.py' cannot be loaded as Python module.
[Fri Dec 28 10:22:08 2012] [error] [client 127.0.0.1] mod_wsgi (pid=3279): Exception occurred processing WSGI script '/var/www/djcode/fugit/fugit/fugit/apache/wsgi.py'.
[Fri Dec 28 10:22:08 2012] [error] [client 127.0.0.1] Traceback (most recent call last):
[Fri Dec 28 10:22:08 2012] [error] [client 127.0.0.1]   File "/var/www/djcode/fugit/fugit/fugit/apache/wsgi.py", line 23, in <module>
[Fri Dec 28 10:22:08 2012] [error] [client 127.0.0.1]     from django.core.wsgi import get_wsgi_application
[Fri Dec 28 10:22:08 2012] [error] [client 127.0.0.1] ImportError: No module named django.core.wsgi

谁能告诉我这里缺少什么?

编辑:

看起来我可能有一个virtualenvwrapper权限问题。我已经尝试按照this answer的建议移动我的virtualenvs,但现在virtualenvwrapper似乎找不到自己。在尝试加载初始化挂钩时,我得到了“[Errno 13]权限被拒绝”。我已经chmod 755新目录,但没有骰子。

进一步编辑: 我通过使用nginx作为gunicorn的反向代理而不是使用Apache进行部署来解决这个问题。它在大约半小时内建立并顺利运行。

0 个答案:

没有答案