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

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

我似乎在使用 mod_wsgi 部署 django 时遇到了问题。过去我使用过 mod_python,但我想进行更改。我一直在使用 Graham Dumpleton 注释http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango1,但似乎仍然不起作用。我收到内部服务器错误。

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.

答案1

您可以为此设置 WSGI 变量。在您的 Apache 配置中:

WSGIPythonEggs /var/tmp

这与设置环境变量相同PYTHON_EGG_CACHE,正如topdog的答案所指出的,它仅适用于mod_python。

答案2

这可能是 SELInux 权限问题。这是 RedHat Linux 还是 RedHat 变体(例如 CentOS 或 Scientific Linux)?如果是,您可能需要禁用 SELinux(通常不推荐)或设置目录的文件上下文。Debian(及其变体)默认禁用 SELinux,但 RedHat 和 CentOS 默认启用它。

对于您读取/写入的任何文件/目录,您可以使用此命令来更改文件上下文:

sudo chcon system_u:object_r:httpd_sys_rw_content_t:s0 (上传文件夹名称)

根据我对 mod_wsgi 编译/安装的经验,我给出了这个帖子,可能会有用:

使已编译的 Python mod_wsgi 模块在具有 SElinux 强制模式的 Apache 服务器上运行. 如果这有帮助的话请告诉我。

答案3

在你的 Apache 配置中设置此项

SetEnv PYTHON_EGG_CACHE /var/tmp

相关内容