Next.js Discord

Discord Forum

Mapping different domains to folder paths of the same NextJS app on Vercel

Answered
White-crowned Sparrow posted this in #help-forum
Open in Discord
White-crowned SparrowOP
I have a situation like this:

- My main app is main.example.com

- My customers create folders in the app where their stuff is at main.example.com/customer1, main.example.com/customer2 etc

- My customers now want to map their own custom domain to a folder, e.g. customer1.example.com maps to main.example.com/customer so that when the user visits customer1.example.com the files in in main.example.com/customer1 are served but the URL does not change and the visitor to the site always sees customer1.example.com in the URL bar

What is the best way to achieve this on Vercel? Do I have to have a separate Nginx server running somewhere to configure the reverse proxy, or does Vercel provide some sort of built-in/elegant solution for these situations?
Answered by joulev
Vercel does support this natively, but that requires you to move the nameservers of the domain to Vercel.

Check https://github.com/vercel/platforms and https://vercel.com/docs/projects/domains/working-with-domains#wildcard-domain
View full answer

6 Replies

Answer
@joulev Vercel does support this natively, but that requires you to move the nameservers of the domain to Vercel. Check https://github.com/vercel/platforms and <https://vercel.com/docs/projects/domains/working-with-domains#wildcard-domain>
White-crowned SparrowOP
Hi - thank you. In my case the customer has their own domain, not a need to get a subdomain under my domain. Is that possible?
@White-crowned Sparrow Hi - thank you. In my case the customer has their own domain, not a need to get a subdomain under my domain. Is that possible?
White-crowned SparrowOP
Thank you for the helpful information. I think I'm starting to figure this out. My question is here:

My remaining question is regarding this: https://github.com/vercel/platforms/blob/29e20e790eaf17d4d5051c23a69636dce724c174/app/%5Bdomain%5D/%5Bslug%5D/page.tsx

How do you map a customer's domain (e.g., customer1.example.com) to the [domain] portion of the URL?