Request 400 while NGINX Server Block with Django

While I was working on a project requiring multiple website hosted in a same server, I encountered a random issues which happened when request 400 started to pop up in every server blocks I had setup earlier.

After checking all the server blocks incoming request. I discovered that the if I requested domain name started with www., the traffic will be routed to one of my server blocks with. Since I only allowed request from the server name to pass through, other domain trying to request the server block will result in a request 400 error.

Hence, a good way to counter this issues is to server name with both names( with www. and without www.) . Also remember to set the allowed_host in django settings file to both names .

Although I also found out that setting it to accept all incoming request would yield the same result. Since Nginx will only redirect traffic to their own local server, maybe it will be a better option to simply set it to wild .

Show your support

Clapping shows how much you appreciated theblackcat102’s story.