0

我有,这个 httpd.conf

NameVirtualHost *:80
<VirtualHost *:80>
    ServerName www.hello2.ch
    DocumentRoot /home/django_www/hello
    WSGIScriptAlias / /var/www/django_www/hardi/django.wsgi
    ErrorLog /var/www/django_www/hardi/error_log
    CustomLog /var/www/django_www/hardi/access_log common
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /var/www/html
</VirtualHost>

vi /etc/hosts

127.0.0.1       localhost.localdomain localhost
128.178.131.89  www.hello2.ch
128.178.131.89  ohtersite.ch

python 2.5,mod_wsgi-2.5,/root/epd-5.1.0/lib/libpython2.5.so.1.0:安装!

ldd /root/epd-5.1.0/bin/python

libpython2.5.so.1.0 => /root/epd-5.1.0/lib/libpython2.5.so.1.0 (0x00002b1bb7333000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003da0600000)
libdl.so.2 => /lib64/libdl.so.2 (0x0000003d9fe00000)
libutil.so.1 => /lib64/libutil.so.1 (0x0000003dadc00000)
libm.so.6 => /lib64/libm.so.6 (0x0000003da0200000)
libc.so.6 => /lib64/libc.so.6 (0x0000003d9fa00000)
/lib64/ld-linux-x86-64.so.2 (0x0000003d9f600000)

回声 $LD_LIBRARY_PATH

/root/epd-5.1.0/lib/

但是当我尝试加载网页时,我得到以下error_log:

'import site' failed; use -v for traceback
[Wed Aug 29 11:52:57 2012] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Wed Aug 29 11:52:57 2012] [notice] Digest: generating secret for digest authentication ...
[Wed Aug 29 11:52:57 2012] [notice] Digest: done
[Wed Aug 29 11:52:57 2012] [notice] mod_python: Creating 4 session mutexes based on 256 max processes and 0 max threads.
[Wed Aug 29 11:52:57 2012] [notice] Apache/2.2.3 (Red Hat) configured -- resuming normal operations
[Wed Aug 29 11:55:00 2012] [error] [client 66.249.72.187] Symbolic link not allowed or link target not accessible: /var/www/html/app/webroot/w3
[Wed Aug 29 11:58:30 2012] [error] [client 66.249.72.187] Symbolic link not allowed or link target not accessible: /var/www/html/app/webroot/w3
[Wed Aug 29 12:01:58 2012] [error] [client 66.249.72.187] Symbolic link not allowed or link target not accessible: /var/www/html/app/webroot/w3
[Wed Aug 29 12:05:30 2012] [error] [client 66.249.72.187] Symbolic link not allowed or link target not accessible: /var/www/html/app/webroot/w3
[Wed Aug 29 12:09:00 2012] [error] [client 66.249.72.187] Symbolic link not allowed or link target not accessible: /var/www/html/app/webroot/w3
[Wed Aug 29 12:12:29 2012] [error] [client 66.249.72.187] Symbolic link not allowed or link target not accessible: /var/www/html/app/webroot/w3
[Wed Aug 29 12:14:06 2012] [error] [client 178.33.137.225] Symbolic link not allowed or link target not accessible: /var/www/html/app/webroot/w3
[Wed Aug 29 12:15:59 2012] [error] [client 66.249.72.187] Symbolic link not allowed or link target not accessible: /var/www/html/app/webroot/w3
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
'import site' failed; use -v for traceback
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
....
'import site' failed; use -v for traceback
[Wed Aug 29 12:17:47 2012] [notice] caught SIGTERM, shutting down
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
'import site' failed; use -v for traceback
[Wed Aug 29 12:17:47 2012] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Wed Aug 29 12:17:47 2012] [notice] Digest: generating secret for digest authentication ...
[Wed Aug 29 12:17:47 2012] [notice] Digest: done
[Wed Aug 29 12:17:47 2012] [notice] mod_python: Creating 4 session mutexes based on 256 max processes and 0 max threads.
[Wed Aug 29 12:17:47 2012] [notice] Apache/2.2.3 (Red Hat) configured -- resuming normal operations
[Wed Aug 29 12:18:01 2012] [error] Traceback (most recent call last):
[Wed Aug 29 12:18:01 2012] [error]   File "/var/www/django_www/hardi/django.wsgi", line 1, in <module>
[Wed Aug 29 12:18:01 2012] [error]     import os
[Wed Aug 29 12:18:01 2012] [error] ImportError: No module named os

任何想法,如何使 Django 与 mod_wsgi 一起工作,以及如何使第一个 VirtualHost 条目与 www.hello2.ch 网页以及第二个 VirtualHost 条目中的所有其他条目相匹配?

4

2 回答 2

1

Run 'ldd' on the mod_wsgi.so.

The problem is likely that it is finding a different Python version. It can also be that since your Python is not in a standard location, that it doesn't know where to find the installation.

In the latter case, add at global scope, outside of VirtualHost, in your Apache configuration:

WSGIPythonHome /root/epd-5.1.0

The value should correspond to the value of sys.prefix printed from your Python when run.

import sys
print sys.prefix
于 2012-08-29T23:28:09.887 回答
0

根据您遇到的错误,似乎有几件事可能正在发生。但是,我不会将所有这些都放入评论中,而是继续发布作为答案。

在我的 django.wsgi 文件中,我有以下两行更改 PATH 环境变量以让 python 从我的 django 项目中导入包:

import sys
sys.path.append('/path/to/mysite.com/app/mydjangoproject')

您还需要确保在您将使用 django的httpd.conf内部添加以下内容:VirtualHost

<Directory /path/to/mysite.com/app/mydjangoproject>
    Order allow,deny
    Allow from all
</Directory>

编辑:

关于您在错误消息中出现的评论中提到的符号链接,我不太确定该怎么做。如果您只是尝试使用它来允许 apache 访问 DocumentRoot 之外的资源,则需要添加包含符号链接的Options FollowSymLinks指令Directory

于 2012-08-29T12:27:48.280 回答