调试Apache / Django / WSGI错误请求(400)错误 [英] Debugging Apache/Django/WSGI Bad Request (400) Error

查看:131
本文介绍了调试Apache / Django / WSGI错误请求(400)错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的简单Django应用程序在调试模式下工作正常( manage.py runserver ),并在我的开发框上的WSGI + Apache下工作,但是当我推送到EC2 I对于我尝试查看的任何网址(无论是在我的应用程序还是在Django管理员中),开始收到间歇性(10-80%的时间)错误错误请求(400)

My simple Django app worked fine in debug mode (manage.py runserver), and works under WSGI+Apache on my dev box, but when I pushed to EC2 I began receiving intermittent (10-80% of the time) errors of Bad Request (400) for any URLs I try to view (whether in my app or in the Django admin.

在哪里可以找到关于这个的调试信息?没有什么出现在 /var/log/apache2/error.log中 ,即使使用 LogLevel = info 。我已经检查了版本,记录了请求环境(参见 ModWSGI调试提示),并没有看到重大差异。

Where can I find debug information about this? Nothing appears in /var/log/apache2/error.log, even with LogLevel=info. I have checked versions, logged the Request environment (cf. ModWSGI Debugging Tips) and see no major differences.

剩下的一个想法是,我正在使用来自Ubuntu 12.04(libapache2-mod-wsgi 3.3-4build1)的mod_wsgi是针对Python 2.7.1构建的,我有Python 2.7.3,而Django是1.6,比Ubuntu Precise版本新,我犹豫开始构建包从s因为它很难清理,这些似乎是次要的版本更改...

The one remaining thought I had is, I'm using the mod_wsgi from Ubuntu 12.04 (libapache2-mod-wsgi 3.3-4build1) which was built against Python 2.7.1; I have Python 2.7.3. And Django is 1.6, which is newer than the Ubuntu Precise version. I hesitate to start building packages from source since it's so hard to clean up and these seem like minor version changes...

感谢您的帮助。

(参考,这里是Apache配置和WSGI应用程序)

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www
    WSGIScriptAlias /rz /usr/local/share/rz/rz.wsgi
    ...



rz.WSGI应用程序



rz.WSGI app

import os
import sys
import django.core.handlers.wsgi
import pprint

path = '/usr/local/share/rz'
if path not in sys.path:
    sys.path.insert(0, path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'rz.settings'

class LoggingMiddleware:
    def __init__(self, application):
        self.__application = application

    def __call__(self, environ, start_response):
        errors = environ['wsgi.errors']
        pprint.pprint(('REQUEST', environ), stream=errors)

        def _start_response(status, headers, *args):
            pprint.pprint(('RESPONSE', status, headers), stream=errors)
            return start_response(status, headers, *args)

        return self.__application(environ, _start_response)

application = LoggingMiddleware(django.core.handlers.wsgi.WSGIHandler())


推荐答案

将ALLOWED_HOSTS设置添加到您的settings.py中,如此...

Add the ALLOWED_HOSTS setting to your settings.py like so...

ALLOWED_HOSTS = [
    '.example.com', # Allow domain and subdomains
    '.example.com.', # Also allow FQDN and subdomains
]

我有同样的问题,找到答案这里是文档

I had this same problem and found the answer here in the docs

update:django 1.6文档不再在线,我更新了链接,以转到django 1.7文档 ALLOWED_HOSTS 设置。

update: django 1.6 docs are no longer online, I updated the link to go to the django 1.7 docs for ALLOWED_HOSTS setting.

这篇关于调试Apache / Django / WSGI错误请求(400)错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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