2012-04-08 57 views
0

我认为我的apache2服务器已接近设置,但它仍然返回500错误。这里是我的.wsgi文件:Django EC2的mod_wsgi配置与Apache不工作

import os, sys 

#path to directory of the .wsgi file ('apache/') 
wsgi_dir = os.path.abspath(os.path.dirname(__file__)) 

#path to project root directory (parent of 'apache/') 
project_dir = os.path.dirname(wsgi_dir) 

sys.path.append(project_dir) 
project_settings = os.path.join(project_dir, 'settings') 
os.environ['DJANGO_SETTINGS_MODULE'] = 'ecomstore.settings' 
import django.core.handlers.wsgi 
application = django.core.handlers.wsgi.WSGIHandler() 

这里是我的virtualhost文件:

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

     Alias /static /home/ecomstore/static 

     DocumentRoot /home/ecomstore 
     WSGIScriptAlias//home/ecomstore/apache/ecomstore.wsgi 

     ErrorLog /var/log/apache2/error.log 

     LogLevel warn 

     CustomLog /var/log/apache2/access.log combined 

</VirtualHost> 

这里是我的服务器重启:

sudo /etc/init.d/apache2 restart 
* Restarting web server apache2 
[Sun Apr 08 02:47:31 2012] [warn] module wsgi_module is already loaded, skipping 
... waiting ..........[Sun Apr 08 02:47:42 2012] [warn] module wsgi_module is already loaded, skipping 
    ...done. 

然而,即使我与国防部 - 没有错误wsgi配置重启,我仍然遇到前面提到的500内部服务器错误。有什么我失踪?

回答

0

您需要从提出请求时开始查看Apache错误日志,而不是在重新启动时查看。

问题的一个来源是sys.path不包含项目目录的父目录,因为您设置了DJANGO_SETTINGS_MODULE,所以这将是必需的。去阅读有关此要求:

http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

,并修复它。

除此之外,您需要确定它是否是Apache 500页面或Django页面。如果它是Django的,那么在Django设置文件中打开DEBUG并重新启动Apache,以便在浏览器中显示完整的错误。解决问题后关闭DEBUG。

+0

是的,我检查了日志,发现这:'ImportError:无法导入设置'ecomstore.settings'(它是否在sys.path?是否有语法错误?):没有模块名为ecomstore.settings ' – locoboy 2012-04-08 09:19:51

+0

固定上面的问题通过添加'sys.path.append('/ home')' – locoboy 2012-04-08 10:29:05

+1

顺便说一句,建议将DocumentRoot设置为你所拥有的。如果您稍后填入Apache配置,则所有源代码都可以下载,包括Django设置文件中的数据库密码。切勿将DocumentRoot设置为包含您不希望用户能够看到的敏感内容的位置。 – 2012-04-08 22:46:09