Django Apache mod_wsgi 500 [英] Django Apache mod_wsgi 500

查看:53
本文介绍了Django Apache mod_wsgi 500的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a Django application deployed on CentOS. Here is what my httpd.conf file looks like:

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",
)

这是我的管理员/电子邮件设置:

This is my Admin/Emailing setup:

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.py 设置为 DEBUG = False 时,如果没有看到这个自定义 500.html 页面,我就无法访问我的网站上的任何地方.

In my templates directory, I have defined a custom 500.html file. When I set my settings.py to have DEBUG = False, I cannot get anywhere on my site without seeing this custom 500.html page.

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

What's even more strange is the fact that there are no errors in the log files - so I am unsure of where to look or how to proceed. I know it can see the templates because of my custom 500.html file, but I am not sure what is causing the 500 Internal Server errors.

进一步配置后,我设法得到了一些错误输出(感谢@Matt Stevens),这是日志输出:

After further configuration, I managed to get some errors output (thanks to @Matt Stevens), here is the log output:

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".多亏了错误记录,我终于能够看到这一点.

Turns out I needed to add my IP address to the "ALLOWED_HOSTS" in my settings.py file. Thanks to the error logging, I was finally able to see that.

实际代码:

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

Apache 重启后,一切正常!

After an Apache restart, everything is working properly now!

这篇关于Django Apache mod_wsgi 500的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆