3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Djangoで「Invalid HTTP_HOST header」が出たときの対処

Posted at

事象

Invalid HTTP_HOST header: '*.*.*.*:8000'. You may need to add '*.*.*.*' to ALLOWED_HOSTS.

エラー内容

  • 受け取ったサイト名とDjangoで設定しているサイト名が異なる。

原因

  • 下記が未設定
settings.py
ALLOWED_HOSTS = []

対処①

  • アスタリスク(*)を設定する。
  • セキュリティ的に望ましくないため検証などで利用する。
settings.py
ALLOWED_HOSTS = ['*']

対処②

  • 公開するサイトのFQDNを指定する。
  • 本番サイトなどサイト名が決まっていればこちらが望ましい。
settings.py
ALLOWED_HOSTS = ['www.example.com']

公式ドキュメント

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?