我的 django.wsgi
import os
import sys
sys.path.append('/var/www/django')
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
os.environ['PYTHON_EGG_CACHE'] = '/var/www/django/myapp/.python-eggs'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
http配置文件
<VirtualHost 127.0.0.1:80>
DocumentRoot /var/www/default
ServerName localhost
WSGIScriptAlias /myapp /var/www/django/myapp/apache/django.wsgi
ErrorLog /var/www/django/myapp/logs/error_log
</VirtualHost>
Apache 错误如下
当我访问 localhost/myapp 时它会出现一些服务器错误
[Fri Jun 25 12:42:42 2010] [error] [client 127.0.0.1] File does not exist: /var/www/default/favicon.ico
[Fri Jun 25 12:42:45 2010] [error] [client 127.0.0.1] File does not exist: /var/www/default/favicon.ico
[Fri Jun 25 12:42:48 2010] [info] [client 127.0.0.1] mod_wsgi (pid=3585, process='', application='localhost|/myapp'): Loading WSGI script '/var/www/django/myapp/apache/django.wsgi'.
[Fri Jun 25 12:42:48 2010] [error] [client 127.0.0.1] mod_wsgi (pid=3585): Target WSGI script '/var/www/django/myapp/apache/django.wsgi' cannot be loaded as Python module.
[Fri Jun 25 12:42:48 2010] [error] [client 127.0.0.1] mod_wsgi (pid=3585): Exception occurred processing WSGI script '/var/www/django/myapp/apache/django.wsgi'.
[Fri Jun 25 12:42:48 2010] [error] [client 127.0.0.1] Traceback (most recent call last):
[Fri Jun 25 12:42:48 2010] [error] [client 127.0.0.1] File "/var/www/django/myapp/apache/django.wsgi", line 8, in <module>
[Fri Jun 25 12:42:48 2010] [error] [client 127.0.0.1] import django.core.handlers.wsgi
[Fri Jun 25 12:42:48 2010] [error] [client 127.0.0.1] File "/opt/python2.6/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 1, in <module>
[Fri Jun 25 12:42:48 2010] [error] [client 127.0.0.1] from threading import Lock
[Fri Jun 25 12:42:48 2010] [error] [client 127.0.0.1] File "/opt/python2.6/lib/python2.6/threading.py", line 13, in <module>
[Fri Jun 25 12:42:48 2010] [error] [client 127.0.0.1] from functools import wraps
[Fri Jun 25 12:42:48 2010] [error] [client 127.0.0.1] File "/opt/python2.6/lib/python2.6/functools.py", line 10, in <module>
[Fri Jun 25 12:42:48 2010] [error] [client 127.0.0.1] from _functools import partial, reduce
[Fri Jun 25 12:42:48 2010] [error] [client 127.0.0.1] ImportError: /opt/python2.6/lib/python2.6/lib-dynload/_functools.so: failed to map segment from shared object: Permission denied
ldd 的输出:
linux-gate.so.1 => (0x0098c000)
libpython2.6.so.1.0 => /usr/lib/libpython2.6.so.1.0 (0x00423000)
libpthread.so.0 => /lib/libpthread.so.0 (0x005cd000)
libdl.so.2 => /lib/libdl.so.2 (0x00110000)
libutil.so.1 => /lib/libutil.so.1 (0x006d8000)
libm.so.6 => /lib/libm.so.6 (0x00778000)
libc.so.6 => /lib/libc.so.6 (0x00a46000)
/lib/ld-linux.so.2 (0x002e5000)
我尝试了 import sys,apace 中没有错误,唯一的一行是
[Mon Jun 28 13:33:24 2010] [info] [client 127.0.0.1] mod_wsgi (pid=19384, process='', application='python.localhost|/application'): Loading WSGI script '/var/www/application/application.wsgi'.
答案1
什么平台?操作系统安装的 Python 的确切版本是什么?/opt/python2.6 中安装的 Python 的确切版本是什么?当您对已安装的 mod_wsgi Apache 模块 .so 文件执行“ldd mod_wsgi.so”时会得到什么?您是否恰好在配置中设置了 WSGIPythonHome?
总的来说,这看起来有点像你可能正在选择不同版本的 Python 共享库或安装 Python lib 目录,并且存在不兼容性。
另外返回并获取一个运行的 hello world WSGI 脚本而不是 Django,当它运行时添加:
import threading
所以你可以看看是否可以创建一个独立测试,用于调查 Django 之外发生的事情。
有关 hello world 示例,请参阅:
http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide
最后,为了确保万无一失,请确保您没有在同一个 Apache 实例中加载 mod_python。
答案2
您的网络服务器是否对 /var/www/django/myapp/.python-eggs 具有写权限?
答案3
似乎可以通过禁用 SELinux 来解决问题,尽管没有多少人会这样做。另一种方法是尝试为试图访问的文件设置适当的权限和上下文(不要问我!)
这里 (https://stackoverflow.com/questions/2685994/django-deploy-trouble) 似乎已经解决了这个问题,但我还没有检查过。