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

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

问题描述

我简单Django应用程序的工作在调试模式下( manage.py的runserver )的罚款,并在WSGI + Apache的作品在我的dev的盒子,但是当我推到EC2我开始接受间歇(时间10-80%)错误请求(400)的错误,因为我尝试查看(网址任何不论是在我的应用程序或Django管理。

我在哪里可以找到这个调试信息?没有出现在 /var/log/apache2/error.log ,甚至 = LogLevel的信息。我已经检查版本,登录请求环境(参见<一个href=\"https://$c$c.google.com/p/modwsgi/wiki/DebuggingTechniques#Displaying_Request_Environment\">ModWSGI调试提示),看看没有大的差异。

剩下的一个以为我是,我使用的是从的mod_wsgi Ubuntu的12.04它始建反对的Python 2.7.1(中的libapache2-MOD-WSGI 3.3-4build1);我的Python 2.7.3。和Django是1.6,这比Ubuntu的precise版本更新。我毫不犹豫地从源代码开始建立包,因为它是如此难以收拾这些看似微小的变化版本...

谢谢你的帮助。

(仅供参考,这里有Apache的配置和应用程序WSGI)

的Apache配置(000默认)

 &LT;虚拟主机*:80&GT;
    站长的ServerAdmin @本地
    的DocumentRoot的/ var / WWW
    WSGIScriptAlias​​ / RZ /usr/local/share/rz/rz.wsgi
    ...

rz.WSGI应用程序

 导入OS
进口SYS
进口django.core.handlers.wsgi
进口pprint路径='在/ usr / local / share下/ RZ
如果路径不在sys.path中:
    sys.path.insert(0,路径)os.environ ['DJANGO_SETTINGS_MODULE'] ='rz.settings'类LoggingMiddleware:
    高清__init __(个体经营,应用程序):
        自.__应用程序=    高清__call __(个体经营,包围,start_response):
        错误= ENVIRON ['wsgi.errors']
        pprint.pprint(('请求',包围),流=错误)        高清_start_response(状态,头部,*参数):
            pprint.pprint(('反应',地位,头),流=错误)
            返回start_response(状态,头部,*参数)        返回self .__应用(ENVIRON,_start_response)应用= LoggingMiddleware(django.core.handlers.wsgi.WSGIHandler())


解决方案

添加ALLOWED_HOSTS设置为您settings.py像这样...

  ALLOWED_HOSTS = [
    .example.com的'#允许域和子域
    .example.com的。',#也让FQDN和子域
]

我有这个同样的问题,在这里找到了答案在docs

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.

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.

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...

Thank you for your help.

(For reference, here are the Apache config and WSGI apps)

Apache config (000-default)

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www
    WSGIScriptAlias /rz /usr/local/share/rz/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())

解决方案

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

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

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