Apache Wsgi virtualHost,Django虚拟环境“没有名为django.core.wsgi的模块”

Apache Wsgi virtualHost, Django virtual env “no module named django.core.wsgi”

我已经看到很多以前的消息与我的问题有关,但没有答案可以摆脱我的"500服务器内部错误",所以我尝试发布我的conf以获得帮助。

错误信息:

[Fri Jun 24 17:05:23.631270 2016] [authz_core:error] [pid 15187:tid 140715758237440] [client 127.0.0.1:47873] AH01630: client denied by server configuration: /home/www/waves/

[Fri Jun 24 17:05:23.631568 2016] [:error] [pid 15186:tid 140715648984832] ['/home/marc/.virtualenvs/waves/lib/python2.7/site-packages', '/home/www/waves', '/usr/local/lib/python2.7/dist-packages/setuptools-20.6.7-py2.7.egg', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client']

[Fri Jun 24 17:05:23.631660 2016] [:error] [pid 15186:tid 140715648984832] [remote 127.0.0.1:50665] mod_wsgi (pid=15186): Target WSGI script '/home/www/waves/waves_services/wsgi.py' cannot be loaded as Python module.

[Fri Jun 24 17:05:23.631675 2016] [:error] [pid 15186:tid 140715648984832] [remote 127.0.0.1:50665] mod_wsgi (pid=15186): Exception occurred processing WSGI script '/home/www/waves/waves_services/wsgi.py'.

[Fri Jun 24 17:05:23.631686 2016] [:error] [pid 15186:tid 140715648984832] [remote 127.0.0.1:50665] Traceback (most recent call last):

[Fri Jun 24 17:05:23.631710 2016] [:error] [pid 15186:tid 140715648984832] [remote 127.0.0.1:50665] File"/home/www/waves/waves_services/wsgi.py", line 18, in

[Fri Jun 24 17:05:23.631731 2016] [:error] [pid 15186:tid 140715648984832] [remote 127.0.0.1:50665] from django.core.wsgi import get_wsgi_application

[Fri Jun 24 17:05:23.631743 2016] [:error] [pid 15186:tid 140715648984832] [remote 127.0.0.1:50665] ImportError: No module named django.core.wsgi

我的django应用程序没有加载在apache wsgi模式,我尝试了很多解决方案,但仍然无法正常工作。 这是我的confs文件:
虚拟主机:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<VirtualHost *:80>

ServerName dev.www.waves.com
ServerAlias www.waves.com
ServerAdmin [email protected]

DocumentRoot /home/www/waves
Alias media/ /home/www/waves/media/
Alias static/ /home/www/waves/static/

<Directory /home/www/waves>
   Require all granted
</Directory>

<Directory /home/www/waves/staticfiles>
   Require all granted
</Directory>

<Directory /home/www/waves/media>
   Require all granted
</Directory>

WSGIDaemonProcess waves python-path=/home/marc/.virtualenvs/waves/lib/python2.7/site-packages:/home/www/waves
WSGIProcessGroup waves
WSGIScriptAlias /waves /home/www/waves/waves_services/wsgi.py

<Directory /home/www/waves/waves_services>
  <Files wsgi.py>
    Require all granted
  </Files>
</Directory>

<Directory /home/marc/.virtualenvs/waves/lib/python2.7/>
Require all granted
</Directory>

我的wsgy.py内容:

1
2
3
4
5
6
7
8
9
from __future__ import unicode_literals
import os
import sys
import site

print sys.path
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE","waves_services.settings.production")
application = get_wsgi_application()

我在apache错误日志中跟踪了sys.path内容,在sys.path中跟踪了virtualenv。
Django安装在这个virtualenv中(我首先尝试安装django'全局'但错误只是转移到我的设置文件中包含的第一个'特定于应用程序'的导入:environ。
使用virtualenvwrapper创建虚拟环境(任何影响?)

我也试过改变virtualenv文件的所有权,改变了'执行'标志,但我仍然得到这个... 500服务器错误。

我很想知道发生了什么!
thanxs


要检查的几件事。

  • 确保virtualenv有django(pip freeze | grep django)
  • 检查apache用户是否可以通过检查文件夹权限来访问virtualenv
  • 如果您使用的是apache 2.4 +更改以下内容

    Order deny,allow
    Allow from all

    Require all granted

  • 由@marcoooo(OP)建议编辑:不要将virtualenv基础目录放在没有'x'标志的任何家庭目录下,apache www-data用户将无法激活virtualenv ....许多thanxs 到e4c5寻求帮助,救了我的一天(和夜晚)