3

I am running a Django Project on DigitalOcean (using Nginx, Gunicorn and Postgres), and I have specified the "allowed hosts" in the settings.py like this:

ALLOWED_HOSTS = ['sub.domain.tld']

Based on what DigitalOcean already set themselves, and based on a blog post I found, I also modified my Nginx settings for the page (/etc/nginx/sites-available/django) to this:

if ($host !~* ^(sub.domain.tld)$ ) {
    return 444;
}

location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://app.server;
}

I still keep on receiving emails from my Django project, like this one:

"Invalid HTTP_HOST header: '1111.ip138.com'. You may need to add u'1111.ip138.com' to ALLOWED_HOSTS."

When I access the site from my browser, everything seems fine though. Could you let me know where the problem with my configuration is?

Thanks, Tobias

Tobi
  • 139
  • 1
  • 4
  • 3
    Just add proper `server_name` directive to your server block and create another block that will receive and reject connections to all other hosts. – Alexey Ten Apr 06 '15 at 13:53
  • Answer depends on the outcome you want. One of these two answers may help: https://stackoverflow.com/a/17477436/3981745 (your syntax may need a $ at least, on the end) or "Deny before it reaches the backend": https://stackoverflow.com/a/18792080/3981745 – ǝɲǝɲbρɯͽ Apr 06 '15 at 16:29
  • I based my attempt on the first of the two links you provided, and made a mistake writing it down here (without the $). On the server, I wrote the correct syntax, but it still doesn't help. – Tobi Apr 07 '15 at 06:40

0 Answers0