尝试使用mod_wsgi在CentOS 6上使用apache设置Django,但我不确定我的设置是否错误。我已经尝试了很多不同的设置指南,但我总是在apache日志中得到相同的错误:
[Mon Mar 31 19:51:22 2014] [error] [client ::1] mod_wsgi (pid=39608): Target WSGI script '/opt/django/movies/movies/wsgi.py' cannot be loaded as Python module.
[Mon Mar 31 19:51:22 2014] [error] [client ::1] mod_wsgi (pid=39608): Exception occurred processing WSGI script '/opt/django/movies/movies/wsgi.py
[Mon Mar 31 19:51:22 2014] [error] [client ::1] Traceback (most recent call last):
[Mon Mar 31 19:51:22 2014] [error] [client ::1] File "/opt/django/movies/movies/wsgi.py", line 16, in <module>
[Mon Mar 31 19:51:22 2014] [error] [client ::1] from django.core.wsgi import get_wsgi_application
[Mon Mar 31 19:51:22 2014] [error] [client ::1] ImportError: No module named wsgi
wsgi.py
import os
import sys
sys.path.append('/opt/django/movies/movies')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
/etc/httpd/conf/httpd.conf中
<VirtualHost *:80>
WSGIScriptAlias / /opt/django/movies/movies/wsgi.py
ServerName localhost
DocumentRoot "/opt/django/movies"
<Directory /opt/django/movies/movies>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
</VirtualHost>
答案 0 :(得分:0)
安装到mod_wsgi使用的Python安装中的Django版本是旧版本。 django.core.wsgi模块并不总是存在。
您应该了解Python安装mod_wsgi正在使用的内容并更新已安装的Django。参见:
BTW,不要将DocumentRoot设置为使您的Django项目位于该目录下,这是一个安全问题的一步,其中Apache的轻微错误配置可能会暴露您的所有源代码,包括带有密码的设置文件。