简体   繁体   中英

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. I've tried alot of different setup guides but i always get the same error in the apache logs:

[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>

The version of Django installed into the Python installation which mod_wsgi is using is an old version. The django.core.wsgi module didn't always exist.

You should work out what Python installation mod_wsgi is using and update the Django installed. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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