Handle Dynamic Subdomain

is it possible to make railway handle dynamic sub domains like [shop_name].coolstore.com
Solution:
you mean wildcard subdomains?
Jump to solution
37 Replies
Percy
Percy12mo ago
Project ID: N/A
Solution
Fragly
Fragly12mo ago
you mean wildcard subdomains?
Fragly
Fragly12mo ago
if so then yea you just pop in *.coolstore.com as a custom domain
หยอมแหยม
and make backend handle that request that from which sub domain name right?
Fragly
Fragly12mo ago
yes!
หยอมแหยม
lovelyamazed ok! i'll try that tysm
Fragly
Fragly12mo ago
no problem :)
Brody
Brody12mo ago
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?
Fragly
Fragly12mo ago
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 go
หยอมแหยม
hm 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
Fragly
Fragly12mo ago
<: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?
Brody
Brody12mo ago
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
Fragly
Fragly12mo ago
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 🙇‍♂️
Brody
Brody12mo ago
well thats not something i can recommend lol (replying to fragly)
Fragly
Fragly12mo ago
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 salute
Fragly
Fragly12mo ago
happy to help, and good luck! :)
Brody
Brody12mo ago
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
No description
Brody
Brody12mo ago
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
Brody
Brody12mo ago
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?
Brody
Brody12mo ago
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?
Brody
Brody12mo ago
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
Brody
Brody12mo ago
I'm using example names and domains, substitute for your domain names where applicable
หยอมแหยม
alright i get it now 😭 🙇
Brody
Brody12mo ago
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?
Brody
Brody12mo ago
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
Brody
Brody12mo ago
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
Want results from more Discord servers?
Add your server