Software⏱️ 2 min read📅 2026-06-03

How to Fix: How to fix Django error: DisallowedHost at / Invalid HTTP_HOST header: ... You may need to add ... to ALLOWED_HOSTS

Django DisallowedHost error fix

Quick Answer: To fix the Django DisallowedHost error, add your domain to ALLOWED_HOSTS in settings.py. Ensure you're using a valid domain and not just an IP address.

To resolve the DisallowedHost error in Django, you need to configure your project's ALLOWED_HOSTS setting.

🚀 How to Resolve This Issue

Method 1: Update ALLOWED_HOSTS in settings.py

  1. Step 1: Open your project's settings.py file and add the following line to the ALLOWED_HOSTS setting:

Example:

'ALLOWED_HOSTS': ['www.example.com', 'example.com'],

Method 2: Use a reverse proxy server like Nginx or Apache

  1. Step 1: Configure your web server to forward requests from DigitalOcean's IP address to your Django project.

Example Configuration for Nginx:

'server {

listen 80;

    server {

location / {

            proxy_pass http://localhost:8000;

}

    }

By following these steps, you should be able to resolve the DisallowedHost error in Django and access your website successfully.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions