R
Railway•7mo ago
hamzeh_pm

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
Percy
Percy•7mo ago
Project ID: N/A
MantisInABox
MantisInABox•7mo ago
How are you defining your allowed_hosts in settings.py? N/A
hamzeh_pm
hamzeh_pm•7mo ago
firstly how can add my project id 😄 by env variables
MantisInABox
MantisInABox•7mo ago
Just copy it from the URL when viewing your project in the dashboard.
hamzeh_pm
hamzeh_pm•7mo ago
i didn't change them, i just redeploy
MantisInABox
MantisInABox•7mo ago
Okay, yeah, it should just continue to work the same way... hmmm...
hamzeh_pm
hamzeh_pm•7mo ago
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
MantisInABox
MantisInABox•7mo ago
You just paste your project ID here in the chat... but it's not 100% necessary
hamzeh_pm
hamzeh_pm•7mo ago
2e4ad3a7-acc7-483d-a4a5-ad7308be043d ok
MantisInABox
MantisInABox•7mo ago
What are the errors that you are receiving?
hamzeh_pm
hamzeh_pm•7mo ago
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
MantisInABox
MantisInABox•7mo ago
Have you tried setting ALLOWED_HOSTS = ["*"] to see if the errors go away?
hamzeh_pm
hamzeh_pm•7mo ago
sure it will go away like this but all in production not advised as you now
MantisInABox
MantisInABox•7mo ago
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.
hamzeh_pm
hamzeh_pm•7mo ago
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
MantisInABox
MantisInABox•7mo ago
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?
hamzeh_pm
hamzeh_pm•7mo ago
2 1 redis and 1 postgres
MantisInABox
MantisInABox•7mo ago
those would not need to go to your allowed hosts, as those are your databases.
hamzeh_pm
hamzeh_pm•7mo ago
but django conecting with them throught env varibles -> container name
MantisInABox
MantisInABox•7mo ago
you would use those as connection strings in your database section of settings.py, not in allowed hosts
hamzeh_pm
hamzeh_pm•7mo ago
yup they work fine
MantisInABox
MantisInABox•7mo ago
allowed hosts are the domains that are allowed access to your app... the database does not contact your app, your app contacts your database
hamzeh_pm
hamzeh_pm•7mo ago
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
MantisInABox
MantisInABox•7mo ago
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?
hamzeh_pm
hamzeh_pm•7mo ago
env.list("DJANGO_ALLOWED_HOSTS", default=["domain_name"]) i have buy domain before i have railway setup
luna
luna•7mo ago
all you should need to add to the ALLOWED_HOSTS is the public domain 🤔
hamzeh_pm
hamzeh_pm•7mo ago
it is already added there as i recall i add custom domain and it gives me a link to copy somewhere in google dashboard
luna
luna•7mo ago
not sure what you mean by that
hamzeh_pm
hamzeh_pm•7mo ago
or the other way around it was 3 month ago google give me some link to past to railway
luna
luna•7mo ago
are you talking about railway's custom domains and the cname it gives you?
hamzeh_pm
hamzeh_pm•7mo ago
yup
MantisInABox
MantisInABox•7mo ago
the cname has nothing to do with your allowed hosts.
hamzeh_pm
hamzeh_pm•7mo ago
you talk about public domain i said it is already setup
MantisInABox
MantisInABox•7mo ago
that just allows your domain to point to your application. if your domain is example.com your allowed host should contain example.com
hamzeh_pm
hamzeh_pm•7mo ago
btw the sites works so it is all setup correct the only problem is some random ip try to run the app from internal
Brody
Brody•7mo ago
locking thread, its great your site works, but this is a harmless log message