在mod_wsgi上部署django应用的问题
我在用mod_wsgi部署django的时候遇到了一些问题。之前我用的是mod_python,但现在想换成mod_wsgi。我参考了Graham Dumpleton的笔记,地址在这里:http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango1,但是似乎还是不行。我遇到了一个内部服务器错误。
django.wsgi 文件:
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 文件:
<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.
2 个回答
在编程中,有时候我们会遇到一些问题,尤其是在使用某些工具或库的时候。这些问题可能会让我们感到困惑,特别是当我们不太了解这些工具的工作原理时。
比如说,当你在写代码的时候,可能会发现某个功能没有按照你的预期工作。这时候,你可能会去网上搜索解决方案,看看其他人是怎么解决类似的问题的。
在这个过程中,你可能会看到很多技术术语和复杂的解释,这些对初学者来说可能会有点难懂。其实,很多时候问题的根源可能很简单,只是我们没有注意到某些细节。
所以,遇到问题时,保持耐心,仔细阅读相关的文档和讨论,逐步理解每个步骤,这样才能更好地解决问题。
# Avoid [Errno 13] Permission denied: '/var/www/.python-eggs' messages
import os
os.environ['PYTHON_EGG_CACHE'] = '/tmp'
Python Egg 是一种模块文件,它们被打包在 zip 文件里。Python Egg 缓存是一个文件夹,Python 会把这些文件解压到这里,以便运行它们。目前,你正在尝试将它们解压到 /.python-eggs 这个文件夹,但你没有权限写入这个文件夹,或者如果这个文件夹不存在,你也没有权限写入根目录 /。
你有两个选择:第一,你可以创建一个 /.python-eggs 文件夹,并设置为所有人都可以写入(或者至少让运行 Apache 的用户可以写入);第二,你可以设置 PYTHON_EGG_CACHE(使用 WSGIPythonEggs 指令),指定一个你有写入权限的文件夹。