How to disable Django's invalid HTTP_HOST error?

前端 未结 11 933
日久生厌
日久生厌 2020-12-04 10:12

Ever since I deployed a site running Django 1.7 alpha (checked out from Git), I\'ve been occasionally receiving error messages with titles like:

\"Inv

11条回答
  •  情书的邮戳
    2020-12-04 11:06

    Another way to block requests with an invalid Host header before it reaches Django is to use a default Apache config with a that does nothing but return a 404.

    
    
    

    If you define this as your first virtual host (e.g. in 000-default.conf) and then follow it with your 'real' , complete with a and any <ServerAlias> entries that you want to match, Apache will return a 404 for any requests with a Host header that does not match or one of your entries. The key it to make sure that the default, 404 is defined first, either by filename ('000') or the first entry in your config file.

    I like this better than the popular solution above because it is very explicit and easy to extend.

提交回复
热议问题