2017-04-19 70 views
0

我在Ubuntu 16.04上将Django网站上传到Apache 2.4服务器。我的服务器正在运行mod_wsgi。我得到一个名为django.core.wsgi的ImportError:No模块。我已经阅读了许多其他解决方案,但似乎没有任何工作。我在想我的错误与我的Python安装(Python 2.7)有关,但我不确定。我wsgi.py,服务器的conf和错误从Apache日志信息如下:Django网站上的500服务器错误 - ImportError:没有名为django.core.wsgi的模块

Apache的错误日志:

[Thu Apr 13 15:51:06.891778 2017] [authz_core:debug] [pid 27832:tid 140404955539200] mod_authz_core.c(809): [client 134.53.122.114:63670] AH01626: authorization result of Require all granted: granted, referer: http://173.255.204.6/ 
[Thu Apr 13 15:51:06.891833 2017] [authz_core:debug] [pid 27832:tid 140404955539200] mod_authz_core.c(809): [client 134.53.122.114:63670] AH01626: authorization result of <RequireAny>: granted, referer: http://173.255.204.6/ 
[Thu Apr 13 15:51:06.891884 2017] [authz_core:debug] [pid 27832:tid 140404955539200] mod_authz_core.c(809): [client 134.53.122.114:63670] AH01626: authorization result of Require all granted: granted, referer: http://173.255.204.6/ 
[Thu Apr 13 15:51:06.891891 2017] [authz_core:debug] [pid 27832:tid 140404955539200] mod_authz_core.c(809): [client 134.53.122.114:63670] AH01626: authorization result of <RequireAny>: granted, referer: http://173.255.204.6/ 
[Thu Apr 13 15:51:06.892105 2017] [wsgi:info] [pid 27831:tid 140404925069056] [remote 134.53.122.114:11921] mod_wsgi (pid=27831, process='site', application='site.com|'): Loading WSGI script '/var/www/site/site/wsgi.py'. 
[Thu Apr 13 15:51:06.892490 2017] [wsgi:error] [pid 27831:tid 140404925069056] [remote 134.53.122.114:11921] mod_wsgi (pid=27831): Target WSGI script '/var/www/site/site/wsgi.py' cannot be loaded as Python module. 
[Thu Apr 13 15:51:06.892504 2017] [wsgi:error] [pid 27831:tid 140404925069056] [remote 134.53.122.114:11921] mod_wsgi (pid=27831): Exception occurred processing WSGI script '/var/www/site/site/wsgi.py'. 
[Thu Apr 13 15:51:06.892532 2017] [wsgi:error] [pid 27831:tid 140404925069056] [remote 134.53.122.114:11921] Traceback (most recent call last): 
[Thu Apr 13 15:51:06.892564 2017] [wsgi:error] [pid 27831:tid 140404925069056] [remote 134.53.122.114:11921] File "/var/www/site/site/wsgi.py", line 9, in <module> 
[Thu Apr 13 15:51:06.892611 2017] [wsgi:error] [pid 27831:tid 140404925069056] [remote 134.53.122.114:11921]  from django.core.wsgi import get_wsgi_application 
[Thu Apr 13 15:51:06.892647 2017] [wsgi:error] [pid 27831:tid 140404925069056] [remote 134.53.122.114:11921] ImportError: No module named django.core.wsgi 

wsgy.py:

import os, sys 

sys.path.append('/var/www/site') 

from django.core.wsgi import get_wsgi_application 

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "site.settings") 

application = get_wsgi_application() 

的Apache的conf:

<VirtualHost *:80> 
     ServerName site.com 
     ServerAlias www.site.com 
     ServerAdmin [email protected] 
     DocumentRoot /var/www/site 

     WSGIDaemonProcess site python-path=/usr/bin/python 
     WSGIProcessGroup site 

     WSGIScriptAlias//var/www/site/site/wsgi.py process-group=site 

     <Directory /var/www/site/site> 
     <Files wsgi.py> 
     Require all granted 
     </Files> 
     </Directory> 

     Alias /media/ /var/www/site/media/ 
     Alias /static/ /var/www/site/static/ 

     <Directory /var/www/site/static> 
     Require all granted 
     </Directory> 

     <Directory /var/www/site/media> 
     Require all granted 
     </Directory> 

     ErrorLog ${APACHE_LOG_DIR}/error.log 
     CustomLog ${APACHE_LOG_DIR}/access.log combined 
</VirtualHost> 

当我输入which python来查找Python的安装位置时,结果为/usr/bin/python

当我尝试在浏览器中访问我的IP地址时,我收到了500个服务器错误,并在Apache Conf中提供了管理员电子邮件,因此我知道正在使用此文件。

当我通过我的Apache Conf禁用我的wsgi.py文件并访问我的IP地址时,有一个网页可供我浏览我在/var/www/文件夹中的文件。

当我在Python控制台中测试from django.core.wsgi import get_wsgi_application时,它工作正常。

我没有使用virtualenv。

有没有其他的方法可以让我调试这个,或者有人找到了解决这个错误的方法?

+0

@Thameem当我在错误日志中使用相同的输出时,仍然出现服务器错误。 – Kevin

+0

WSGIDaemonProcess网站中的python-PATH =的/ usr/bin中/ Python的 尝试什么,而不是这个 WSGIDaemonProcess网站中的python-PATH = /无功/网络/网站/网站蟒蛇回家=的/ usr/bin中/ Python的 – Thameem

+0

@Thameem我尝试过这些并收到相同的错误。你知道是否有任何方法可以得到更详细的错误信息? – Kevin

回答

0

你需要编辑wsgi.py文件来设置sys.path中,包括包含您的novabucket模块的父目录,大概是这个样子:

进口SYS sys.path.insert(0,' /家庭/ maxmackie/webapps /下的Django/novabucket') 的更多信息,我们的文档中获得:添加到Python和WSGI脚本中的sys.path

务必在进行这些更改后重新启动Apache的。 。

相关问题