Handle Dynamic Subdomain
is it possible to make railway handle dynamic sub domains like
[shop_name].coolstore.com
37 Replies
Project ID:
N/A
Solution
you mean wildcard subdomains?
if so then yea
you just pop in
*.coolstore.com
as a custom domainand make backend handle that request that from which sub domain name right?
yes!
ok! i'll try that tysm
no problem :)
your backend framework would need to be able to do hostname routing, most frameworks support this
have more question
i have 2 web app (admin, store)
so if i want to make whoever access website with sub domain, i want to make it render store
but if user access coolstore.com or dashboard.coolstore.com
i want to make it render admin web instead
how to do that?
I've done this before
You just check whether the subdomain you received is
dashboard
( and it's on the host coolstore.com
in case you add a way to configure custom domains in the future )
and then if it is simply render the dashboard page
if the subdomain isn't coolstore.com
( or on your host ) then route it where it needs to gohm any example?
i still don't get where should i route them with something like
if user redirect 'foo.coolstore.com'
its will render store page using Nuxt 3
but if user redirect to 'dashboard.coolstore.com'
its will render admin management that using Next.js instead
<:mommy_confused:1023749002069540935> you're using two different frameworks for building your apps?
different team sir
like team 1 making store site
and team 2 making admin site
but its just theory
actually i don't know, just give example 🤣
maybe 2 nextjs projects
will nginx solve this problem?
use caddy, heres an example that will get you 80% of the way there
https://github.com/brody192/reverse-proxy/blob/host-matching/Caddyfile
fragly time to learn caddy
I've tried using caddy before, didn't like it, made my own reverse proxy instead
i never heard it before but ill try to research it! tysm 🙇♂️
well thats not something i can recommend lol (replying to fragly)
I live on the edge
don't mind me i'm just 1 year experience with web dev that try to make some lil big project xd
ill update this forum later if its work perfectly or have more question that related this topic
tysm you both again
happy to help, and good luck! :)
sounds good, i wrote that caddyfile so if you have questions feel free to ask
about redirect when user access [shop].coolshop.com
i need to make nginx handling it and redirect user to store service by using private ip right?
or use public ip
I gave you a ready made example that uses caddy, you aren't going to go that route?
yeah i already seen that but i still confuse about reverse proxy a bit
maybe not a bit
well either way, you would absolutely want to use the private domain within the reverse proxy
so i need to add
WEB_HOST_INTERNAL
in private networking?you'd need to set that to one of the internal domains
like create subdomain named
internal-admin.up.railway.app
in admin service and make caddy redirect to that web host right?for a simplistic overview, try to get just this sort of thing working
shop.domain.com
would proxy to shop.railway.internal
domain.com
would proxy to dashboard.railway.internal
oh alright
I'm using example names and domains, substitute for your domain names where applicable
alright i get it now
😭 🙇
that's a public url, use the private domains or else you will be subject to network fees on the two services that you are trying to proxy to
so
.internal
can be used for this situation right?yes, there are no network fees for a service that is only communicated to via the private network
your proxy service is exposed publicly and that is the only service between the 3 that should have network fees
wish I still had the railway project as a demo that went along with the caddyfile that I sent above, but unfortunately I don't, and I don't have the time right now to set that back up