Django Apache mod_wsgi 500

标签 django apache mod-wsgi

我在 CentOS 上部署了一个 Django 应用程序。这是我的 httpd.conf 文件的样子:

WSGISocketPrefix /var/run/wsgi
<VirtualHost *:80>

    WSGIDaemonProcess safe python-path=/usr/lib/python2.6/site-packages
    WSGIProcessGroup safe
    WSGIScriptAlias / /opt/safe/safe/wsgi.py

    <Directory /opt/safe/safe/>
        Order deny,allow
        Allow from all
     </Directory>
</VirtualHost>

编辑:这是我的 TEMPLATE_DIRS
TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    "/opt/safe/static/templates",
    "/var/www/html/static/templates",
)

编辑:这是我的管理员/电子邮件设置:
ADMINS = (
# ('Your Name', 'your_email@example.com'),
('David', 'david@localhost'),
)

SEND_BROKEN_LINK_EMAILS = True

DEFAULT_FROM_EMAIL = 'david@localhost'
SERVER_EMAIL = DEFAULT_FROM_EMAIL

在我的模板目录中,我定义了一个自定义 500.html文件。当我设置我的 settings.pyDEBUG = False ,如果没有看到这个自定义 500.html 页面,我就无法访问我的网站。

更奇怪的是日志文件中没有错误 - 所以我不确定在哪里查看或如何继续。由于我的自定义 500.html 文件,我知道它可以看到模板,但我不确定是什么导致了 500 Internal Server 错误。

编辑:进一步配置后,我设法得到了一些错误输出(感谢@Matt Stevens),这是日志输出:
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 89, in get_response
response = middleware_method(request)
File "/usr/lib/python2.6/site-packages/django/middleware/common.py", line 55, in process_request
host = request.get_host()
File "/usr/lib/python2.6/site-packages/django/http/__init__.py", line 223, in get_host
"Invalid HTTP_HOST header (you may need to set ALLOWED_HOSTS): %s" % host)
SuspiciousOperation: Invalid HTTP_HOST header (you may need to set ALLOWED_HOSTS): [my ip address]

最佳答案

结果我需要将我的 IP 地址添加到我的 settings.py 中的“ALLOWED_HOSTS”中。文件。多亏了错误日志,我终于能够看到这一点。

实际代码:

ALLOWED_HOSTS = ['my.server.ip.address']

Apache 重新启动后,现在一切正常!

关于Django Apache mod_wsgi 500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15097155/

相关文章:

python - Django 在之前已设置外键的同一记录中填充值

php - 允许 laravel 正常工作

apache - 无法理解在 ubuntu 上安装 apache2 的正确方法

python: getfilesystemencoding() 在 shell 和 wsgi 中返回不同的值

python - tastypie 过滤外键相关资源

python - 如何在 Django ModelAdmin 字段集中调用模型方法?

python - 模块未找到错误 : No module named 'sklearn.neighbours'

Apache 虚拟主机 - Mod 代理问题

apache - Solr 索引从 1.4.1 升级到 5.2.1

django - 当使用 django 运行 collectstatic 时,python 模块也被复制是正常的吗?