Spindel
Spindel

Reputation: 289

Why is Django sending me Invalid HTTP_HOST header with my server IP?

So Django is sending me mail with this info:

[Django] ERROR: Invalid HTTP_HOST header: '<my server IP here>'.You may need to add u'<my server IP here>' to ALLOWED_HOSTS.

No stack trace available

Request repr() unavailable.

The problem is... You can't access my website with the server IP because I only allowing domain that already is in the ALLOWED_HOST setting.

So... What should I do?

Edit: I am using Nginx -> Gunicorn. This error only happens sometimes, like 1-2 times per week.

Upvotes: 4

Views: 3251

Answers (1)

Spindel
Spindel

Reputation: 289

Found the reason.

It was when someone tried to access the server via IP over HTTPS, as in https:// (and the server-ip)

The solution is to disable that option.

Solution for Nginx:

server {
    listen      80;
    listen      443 ssl;
    ssl_certificate    /etc/ssl/example.crt;
    ssl_certificate_key    /etc/ssl/example.key;
    return      444;
}

Upvotes: 5

Related Questions