Django的阿帕奇mod_wsgi的500 [英] Django Apache mod_wsgi 500

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

问题描述

我已经部署在CentOS Django应用程序。这里是我的httpd.conf文件看起来像:

  WSGISocket preFIX在/ var /运行/ WSGI
<虚拟主机*:80>    WSGIDaemonProcess安全的python-PATH = / usr / lib目录/ python2.6的/站点包
    WSGIProcessGroup安全
    WSGIScriptAlias​​ / /opt/safe/safe/wsgi.py    <目录/ opt /安全/安全/>
        为了否认,允许
        所有允许
     < /目录>
< /虚拟主机>

编辑:这是我的 TEMPLATE_DIRS

  TEMPLATE_DIRS =(
    #将字符串这里,像/家/ HTML / django_templates或C:/网络/ Django的/模板。
    #请始终使用正斜杠,即使在Windows。
    #不要忘了使用绝对路径,而不是相对路径。
    /选择/安全/静态/模板
    在/ var / www / html等/静态/模板

编辑:这是我的联系/电子邮件发送设置:

  ADMINS =(
#('你的名字','your_email@example.com'),
('大卫','大卫@本地'),
)SEND_BROKEN_LINK_EMAILS = TRUEDEFAULT_FROM_EMAIL ='大卫@本地'
SERVER_EMAIL = DEFAULT_FROM_EMAIL

在我的模板目录中,我已经定义了一个自定义的 500.html 文件。当我把我的 settings.py DEBUG =假,我不能让我的网站上的任何地方,没有看到这个自定义500.html页面。

什么是更奇怪的是,有在日志文件中没有任何错误 - 所以我不确定在哪里看和如何进行。我知道它可以看到,因为我的自定义500.html文件的模板,但我不知道是什么原因造成的500内部服务器错误。

编辑:进一步的配置后,我设法得到了一些错误输出(感谢@马特·史蒂文斯),这里是日志输出:

 回溯(最后最近一次调用):
文件/usr/lib/python2.6/site-packages/django/core/handlers/base.py,行89,在get_response
响应= middleware_method(要求)
文件/usr/lib/python2.6/site-packages/django/middleware/common.py,第55行,在process_request
主机= request.get_host()
文件/usr/lib/python2.6/site-packages/django/http/__init__.py,223线,在get_host
无效HTTP_HOST头(您可能需要设置ALLOWED_HOSTS):%的%主机)
SuspiciousOperation:无效HTTP_HOST头(您可能需要设置ALLOWED_HOSTS):我的IP地址]


解决方案

原来我需要我的IP地址添加到我的 settings.py 文件中的ALLOWED_HOSTS 。多亏了错误日志记录,我终于能看到这一点。

实际code:

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

一个Apache重新启动后,一切正常了!

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>

EDIT: This is my 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",
)

EDIT: 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

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.

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.

EDIT: 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]

解决方案

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.

Actual code:

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

After an Apache restart, everything is working properly now!

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

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