在mod_wsgi上部署django应用程序的问题

问题描述:

我似乎遇到了用mod_wsgi部署django的问题。在过去,我使用mod_python,但我想进行更改。我一直在使用Graham Dumpleton笔记http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango1,但它似乎仍然不起作用。我得到一个内部服务器错误。在mod_wsgi上部署django应用程序的问题

django.wsgi file:

import os 
import sys 

sys.path.append('/var/www/html') 
sys.path.append('/var/www/html/c2duo_crm') 

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

WSGIScriptAlias//var/www/html/c2duo_crm/apache/django.wsgi 

Apache httpd file:

<Directory /var/www/html/c2duo_crm/apache> 
Order allow,deny 
Allow from all 
</Directory> 

在我的Apache的错误日志,它说我有这样的错误这还不是全部的,但我已经得到了最重要的部分:

[Errno 13] Permission denied: '/.python-eggs' 
[Thu Mar 03 14:59:25 2011] [error] [client 127.0.0.1] 
[Thu Mar 03 14:59:25 2011] [error] [client 127.0.0.1] The Python egg cache directory is currently set to: 
[Thu Mar 03 14:59:25 2011] [error] [client 127.0.0.1] 
[Thu Mar 03 14:59:25 2011] [error] [client 127.0.0.1] /.python-eggs 
[Thu Mar 03 14:59:25 2011] [error] [client 127.0.0.1] 
[Thu Mar 03 14:59:25 2011] [error] [client 127.0.0.1] Perhaps your account does not have write access to this directory? You can 
[Thu Mar 03 14:59:25 2011] [error] [client 127.0.0.1] change the cache directory by setting the PYTHON_EGG_CACHE environment 
[Thu Mar 03 14:59:25 2011] [error] [client 127.0.0.1] variable to point to an accessible directory. 

Python Egg s是模块文件是con在zip文件中保存。 Python Egg Cache是​​Python提取它们的目录,所以它可以运行它们。目前,您正试图将它们解压缩到/.python-eggs,但是您没有对该目录的写入权限,或者如果它不存在,则不能写入。您可以创建/.python-eggs并将其设置为全局可写(或者至少可以由Apache运行的用户写入),也可以将PYTHON_EGG_CACHE(使用WSGIPythonEggs directive)设置为一个目录你有写入权限。

+0

我记得当我尝试使用mod_python进行部署时遇到同样的问题。我所做的是我在我的httpd文件中设置了'SetEnv PYTHON_EGG_CACHE/tmp',这会起作用。但是这不适用于mod_wsgi。 – Shehzad009 2011-03-03 16:18:14

+0

您是否尝试使用我链接到的WSGIPythonEggs指令?如果错误消息没有提及/ tmp,那么环境变量没有被识别。 – 2011-03-03 16:22:05

+0

将'WSGIPythonEggs/tmp'放在apache htppd文件中似乎已经可以使其工作。谢谢 – Shehzad009 2011-03-03 16:45:02

# Avoid [Errno 13] Permission denied: '/var/www/.python-eggs' messages 
import os 

os.environ['PYTHON_EGG_CACHE'] = '/tmp'