Django project. allowed host errors with random IPs
i have django project that works fine on my free account, it gets disabled when free accuont finished, started it again with hobby plan with same settings and get random error of allowed_hosts error with random ips
36 Replies
Project ID:
N/A
How are you defining your
allowed_hosts
in settings.py
?
N/Afirstly how can add my project id 😄
by env variables
Just copy it from the URL when viewing your project in the dashboard.
i didn't change them, i just redeploy
Okay, yeah, it should just continue to work the same way...
hmmm...
i mean where in post i add project id, just at the end ?
yup it works without problem
but i got error in my email
it doesn't broke anything just through some errors
You just paste your project ID here in the chat... but it's not 100% necessary
2e4ad3a7-acc7-483d-a4a5-ad7308be043d
ok
What are the errors that you are receiving?
standard allowed host errors
DisallowedHost at /
Invalid HTTP_HOST header: '35.203.191.34:5900'. You may need to add '35.203.191.34' to ALLOWED_HOSTS.
the ip is vary
from time to time
Have you tried setting
ALLOWED_HOSTS = ["*"]
to see if the errors go away?sure it will go away like this
but all in production not advised as you now
Oh, I know.
You can always place your domain there instead of an IP.... as the IP of your container is not always going to stay the same.
i add domain name not ip
1 for my domain, 1 for you can call me thi_name
somename.railway.internal or you can call me somename
i add my domain name and somename
the only things i notice is changed
somename.railway.internal before it is longer name
Internal networking requires you to specify a port... not just the domain...
so it would be
somename.railway.internal:<PORT>
Is another service contacting the django app?2
1 redis and 1 postgres
those would not need to go to your allowed hosts, as those are your databases.
but django conecting with them throught env varibles -> container name
you would use those as connection strings in your database section of settings.py, not in allowed hosts
yup
they work fine
allowed hosts are the domains that are allowed access to your app... the database does not contact your app, your app contacts your database
the only possibility here is some application call the app with ip:port from internal network
and i don't have any other app
or service
the ip is blong to google
i buy my domain from google
do railway have some internal app for google ?
to check something
So, to get this straight, you have
ALLOWED_HOSTS = os.environ['allowed']
for your allowed host environment variable, you have your purchased domain, and your internal network?env.list("DJANGO_ALLOWED_HOSTS", default=["domain_name"])
i have buy domain before i have railway setup
all you should need to add to the
ALLOWED_HOSTS
is the public domain 🤔it is already added there
as i recall i add custom domain and it gives me a link to copy somewhere in google dashboard
not sure what you mean by that
or the other way around it was 3 month ago
google give me some link to past to railway
are you talking about railway's custom domains and the cname it gives you?
yup
the cname has nothing to do with your allowed hosts.
you talk about public domain
i said it is already setup
that just allows your domain to point to your application. if your domain is
example.com
your allowed host should contain example.com
btw the sites works so it is all setup correct
the only problem is some random ip try to run the app from internal
locking thread, its great your site works, but this is a harmless log message