Apache不工作的Django EC2 mod_wsgi配置

Apache不工作的Django EC2 mod_wsgi配置,django,ubuntu,apache2,amazon-ec2,mod-wsgi,Django,Ubuntu,Apache2,Amazon Ec2,Mod Wsgi,我想我的apache2服务器即将安装,但仍然返回500错误。这是我的.wsgi文件: 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(wsg

我想我的apache2服务器即将安装,但仍然返回500错误。这是我的
.wsgi
文件:

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()
NameVirtualHost *:80
 <VirtualHost *:80>
      ServerAdmin admin@site.com
      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>
这是我的
virtualhost
文件:

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()
NameVirtualHost *:80
 <VirtualHost *:80>
      ServerAdmin admin@site.com
      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>

然而,即使在重启时mod wsgi配置没有错误,我仍然会遇到前面提到的500内部服务器错误。我缺少什么吗?

您需要查看发出请求时的Apache错误日志,而不是重新启动时的日志

问题的一个来源是sys.path不包含项目目录的父目录,这是因为您将DJANGO_SETTINGS_模块设置为所必需的。有关此要求,请参阅:

把它修好


除此之外,您还需要确定它是Apache500页面还是Django页面。若它是Django设置文件,那个么在Django设置文件中打开DEBUG并重新启动Apache,这样您就会在浏览器中看到一个完整的错误。解决后关闭调试。

是的,我检查了日志,发现:
ImportError:无法导入设置'ecomstore.settings'(是否在sys.path上?是否有语法错误?):没有名为ecomstore.settings的模块
通过添加
sys.path.append('/home')修复了上述问题。
,将DocumentRoot设置为您拥有的内容是错误的建议。如果稍后填充Apache配置,则可以下载所有源代码,包括Django设置文件中的数据库密码。永远不要将DocumentRoot设置为包含您不希望用户看到的敏感内容的位置。