How to fix django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header

I got this error in production django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: ‘1XX.XX.XX.XX:8000’. You may need to add ‘1XX.XX.XX.XX’ to ALLOWED_HOSTS. My ALLOWED_HOSTS setting is currently set to ALLOWED_HOSTS = [‘*’].

Welcome @daj10 !

When requesting assistance with an error, please post the complete error with the traceback from the server.

Also, please describe your production environment in more detail. What wsgi container are you using? (uwsgi? gunicorn? something else?) What web server are you using? (Nginx? Apache? something else?)

I used WSGI and Apache.

ERROR [exception.py:124] Invalid HTTP_HOST header: '137.00.00.00'. You may need to add ''137.00.00.00'' to ALLOWED_HOSTS.
Traceback (most recent call last):
  File "python3.11/dist-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "python3.11/dist-packages/django/utils/deprecation.py", line 133, in __call__
    response = self.process_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "python3.11/dist-packages/django/middleware/common.py", line 48, in process_request
    host = request.get_host()
           ^^^^^^^^^^^^^^^^^^
  File python3.11/dist-packages/django/http/request.py", line 151, in get_host
    raise DisallowedHost(msg)
django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: '137.00.00.00'. You may need to add '137.00.00.00' to ALLOWED_HOSTS.

What version of Django are you using?

When you say:

Are you referring to mod_wsgi? If so, what does your Apache configuration look like for your project?

Also verify that you do not have multiple entries in your settings.py file for ALLOWED_HOSTS.

I found solution like in the documentation https://docs.djangoproject.com/en/5.0/ref/logging/#django-security. Thanks @KenWhitesell

'django.security.DisallowedHost': {
    'handlers': ['file_disallowed'],
    'propagate': False,
    'level': 'ERROR',
},