简体   繁体   English

使用mod_wsgi在apache上设置Django

[英]Setting up Django on apache with mod_wsgi

Trying to setup Django on apache on CentOS 6 using mod_wsgi but I'm not sure what I have setup wrong. 尝试使用mod_wsgi在CentOS 6的Apache上设置Django,但是我不确定我的设置有误。 I've tried alot of different setup guides but i always get the same error in the apache logs: 我尝试了很多不同的设置指南,但在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 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 /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>

The version of Django installed into the Python installation which mod_wsgi is using is an old version. mod_wsgi使用的Python安装中安装的Django版本是旧版本。 The django.core.wsgi module didn't always exist. django.core.wsgi模块并不总是存在。

You should work out what Python installation mod_wsgi is using and update the Django installed. 您应该确定正在使用的Python安装mod_wsgi并更新已安装的Django。 See: 看到:

BTW, do not set DocumentRoot such that your Django project lives under that directory, it is one step towards being a security problem where a slight misconfiguration of your Apache could expose all your source code, including the settings file with its passwords. 顺便说一句,不要将DocumentRoot设置为使Django项目位于该目录下,这是迈向安全性问题的第一步,在此过程中,对Apache的轻微配置错误可能会暴露所有源代码,包括带有密码的设置文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM