Invalid HTTP_HOST header in Django 1.6.2

I get a lot of invalid HTTP_HOST header messages from my Django web application -

[Django] ERROR: Invalid HTTP_HOST header: "www.bing.com". You may need to add u'www.bing.com 'to ALLOWED_HOSTS

It is used on well-known websites (e.g. bing.com, google.com), as well as on very random websites ( www2t.biglobe.ne.jp, proxy.me5b.ru).

Message in letters:

Missing stack trace available

The repr () request is not available.

I read other questions about this on other SO questions like this and this, and a good blog post like this .

But they all seem to indicate that this problem should have been resolved in Django 1.6. However, I am running Django 1.6.2 and still see this error. I am using Apache WSGI and the application is hosted on AWS Elasticbeanstalk.

Maybe I can suppress these warning messages, but should I expect them first?

+4
source share
3 answers

The problem is not in django or in the django application, it is in the user part.

Your django application is configured to only execute requests on example.com ( ALLOWED_HOSTS ), and then if any other domain specifies the same ip and any user requests that webthe then django will throw this exception.

, bing.con IP- ( Microsoft bing django: -O).

:

  • -.
  • DNS-, -, DNS, .
  • "hosts" , ip.
  • , bing.com .

( ), django :

, , .

+6

, ​​ Django 1.6, LOGGING . , @Devang .

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'null': {
            'class': 'django.utils.log.NullHandler',
        },
    },
    'loggers': {
        'django.security.DisallowedHost': {
            'handlers': ['null'],
            'propagate': False,
        },
    }
}
+4

Django 1.9, docs.

'handlers': {
    'null': {
        'class': 'logging.NullHandler',
    },
},
'loggers': {
    'django.security.DisallowedHost': {
        'handlers': ['null'],
        'propagate': False,
    },
},
0

Source: https://habr.com/ru/post/1531859/


All Articles