Opened 3 years ago
Last modified 3 years ago
#33065 closed Uncategorized
DisallowedHost exception when using server/container name to access django service — at Version 1
Reported by: | Robin | Owned by: | nobody |
---|---|---|---|
Component: | Uncategorized | Version: | 3.2 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Hello,
I am using the Django rest framework to provide REST API to other services.
All services have been packaged in docker. and all services are sharing data via the docker network.
Let's say, App A is calling App B(Django) APIs.
because they are on the same docker network then App A can call it like HTTP://server_B_container_name:8000/api/
But I got a DisallwedHost exception. The error message likes this:
"Invalid HTTP_HOST header: 'training_api'. The domain name provided is not valid according to RFC 1034/1035."
I have set the settings like this.
DJANGO_ALLOWED_HOSTS=localhost,training_api,*
It works if I call it through localhost on the host, or container IP inside App A container or a fully qualified domain name of the host(port 8000 is exposed to host) from other machines.
How can I call the Django via container name from App A, not the IP? the IP will change every time it starts.
Thanks,
Robin