How to fix Invalid HTTP_HOST header error when deploying django project with elasticbeanstalk?


When I deploy my django project to elasticbeanstalk I get the message in the log: "Invalid HTTP_HOST header: ''. You may need to add ''' to ALLOWED_HOSTS." and so on... I have to add 3 ip adresses like the one above in total for the health to be ok and no error/warning messages. Why is this the case? Where are these domains/IP addresses coming from? Is there any more convenient way to fix this so that I don't have to add random IP adresses to the array ALLOWED_HOSTS = [""] in

I created a file and directories in .ebextensions/nginx/conf.d/myconf.conf. This was because according to, it says "To extend Elastic Beanstalk's default nginx configuration, add .conf configuration files to a folder named .ebextensions/nginx/conf.d/".


if ( $host !~* ^(""|"")$ ) {
return 444;

This didn't work it still gives the same message as before.

The way I interpret it is that my django project is on an AWS physical server somewhere and nginx is a middleman between that and my browser. My understanding of Django and AWS is quite basic so I would appreciate it if the answer was as simple as possible.

Thanks in advance!

EDIT1: In a file located at ./.platform/nginx/conf.d/system_config.conf, where . is the project root directory, meaning in the same directory as

server {


location / {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;

proxy_set_header Host $host;: This directive sets the value of the "Host" header forwarded to the backend server. It ensures that the backend server knows the original hostname the user requested.

proxy_set_header X-Real-IP $remote_addr;: This directive sets the value of the "X-Real-IP" header forwarded to the backend server. It is used to send the actual IP address of the client (user) making the request to the backend server.

Maybe I am mistaken but shouldn't my code above work? It doesn't, it still gives me the same error "You may need to add ''' to ALLOWED_HOSTS."

asked 3 months ago425 views
1 Answer


Wouldn't it be resolved if you set "ALLOWED_HOSTS" to "*" as shown below?

profile picture
answered 3 months ago
profile picture
reviewed 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions