我创建了一个名为' pyapps
'并在其中安装了pinax和django。我已经安装了apache 2和mod_wsgi.I创建了一个名为' apache
'的目录。在我的django项目(testproject
)内并放置' django.wsgi
'该目录中的文件。这是我的wsgi文件的内容:
import os
import sys
# put the Django project on sys.path
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../")))
os.environ['DJANGO_SETTINGS_MODULE'] = 'textpisodes.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
然后我创建了一个目录' /check/www
'并将我的项目文件夹和pyapps
文件夹放在&{39; /check/www
' .I chmoded 777 /check/www
上。
最后我创建了一个虚拟主机,它的内容如下:
<VirtualHost *:80>
ServerAdmin myemail
ServerName djangoserver
WSGIDaemonProcess textpisodes user=rajat threads=10 python-path=/check/www
WSGIProcessGroup textpisodes
WSGIScriptAlias / /check/www/textpisodes/apache/django.wsgi
<Directory /check/www/textpisodes/apache>
Order deny,allow
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
LogLevel warn
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
现在,当我尝试访问&#39; http:// djangoserver&#39;时,我得到的只是Internal Server Error
。以下是我的apache日志文件的内容。
[Thu Sep 13 18:39:51 2012] [error] [client 127.0.0.1] mod_wsgi (pid=4890): Target WSGI script '/check/www/textpisodes/apache/django.wsgi' cannot be loaded as Python module.
[Thu Sep 13 18:39:51 2012] [error] [client 127.0.0.1] mod_wsgi (pid=4890): Exception occurred processing WSGI script '/check/www/textpisodes/apache/django.wsgi'.
[Thu Sep 13 18:39:51 2012] [error] [client 127.0.0.1] Traceback (most recent call last):
[Thu Sep 13 18:39:51 2012] [error] [client 127.0.0.1] File "/check/www/textpisodes/apache/django.wsgi", line 9, in <module>
[Thu Sep 13 18:39:51 2012] [error] [client 127.0.0.1] import django.core.handlers.wsgi
[Thu Sep 13 18:39:51 2012] [error] [client 127.0.0.1] ImportError: No module named django.core.handlers.wsgi
答案 0 :(得分:2)
您需要添加虚拟环境路径,以便apache / python可以在那里找到模块。
将其置于您的apache配置中(VirtualHost
条目之外)
WSGIPythonPath /home/me/virtualenv/env1/lib/python2.7/site-packages
或者将其放入wsgi文件中的sys.path
。