I have deployed a Next.js app in Vercel that renders a subdomain based content and I have already linked my domain to that project.
Project Deploy URL: *.mysite.com
Here, If John opens john.mysite.com, it will render content for John's profile.
Same for Mary, mary.mysite.com renders Mary's content.
Now, I want to let John and Mary connect custom domain pointing their subdomain on my app, like www.john.com will display John's content on my website, same for Mary.
This is my DNS configuration on CLoudflare.

The subdomains are splitted into 3 parts and each part has their own Next.js project pointing to that subdomain.
- root domain and www for landing page.
- app subdomain for admin page, where users can create their subdomain based content.
- remaining all subdomains are matched by user generated subdomain's content.
I want to know how do do this. Just like adding custom domain to blogspot blog, imagine john.mysite.com is default blogspot url and www.john.com is custom domain.
Edit after answer:
john.com is using CLoudflare nameservers and this is the current DNS configuration for john.com. I too tried all vercel ip shown above to test if any works and this is my current one.
| Type | Name | Content |
|-------|------------|--------------------|
| A | john.com | 76.76.21.21 |
| CNAME | www | john.mysite.com |
| CNAME | * | my-app.vercel.app |
This is giving me this result for both john.com and www.john.com but john.mysite.com is correctly giving me John's profile.

Also, the deployment URL provided by vercel cannot be used to load user's profile, like the deployment URL my-app.vercel.app tries to render profile for user with id my-site, so only custom domain like john.mysite.com can be used to load user profiles.
Edit 2:
I added following dns records to john.com and result is same.
| NS | mysite.com | ns1.vercel-dns.com |
| NS | mysite.com | ns2.vercel-dns.com |
You have a Next.js app deployed on Vercel that serves different content based on the subdomain (e.g.,
john.mysite.comandmary.mysite.com).You want to map external custom domains (e.g.,
www.john.comandwww.mary.com) to these subdomains.That would involve configuring DNS records to point custom domains to the Vercel-hosted subdomains, and potentially involves Vercel's support for custom domain configurations within their platform.
Based on "Vercel / Adding & Configuring a Custom Domain", you would need first to add a wildcard domain to your Vercel project:
*.mysite.comand add it as a wildcard domain. That will allow any subdomain ofmysite.comto be directed to your Vercel project.Then configure DNS settings for each custom domain:
john.com), you need to configure it with an A record pointing to the IP address provided by Vercel.www.john.com), you should configure it with a CNAME record pointing to the alias Vercel provides for your deployment.If required, you might have to verify access to the domain, especially if it is already in use by another Vercel account. You would do this by adding a TXT record in your DNS settings.
You might consider using Vercel Nameservers (optional but recommended).
If you want to leverage Vercel's full CDN and performance benefits, you can change your domain's nameservers to Vercel's nameservers. In your domain registrar's panel, replace your current nameservers with those provided by Vercel.
Once you have configured the DNS settings or updated the nameservers, Vercel will verify the domain. It may take some time to propagate. After verification, the domain's status in your Vercel dashboard will update, confirming it is ready for use. See also "How can I manage my Vercel DNS records? / Verifying DNS Records"
With this configuration, each of your users can have a custom domain that points to their respective subdomains on your Next.js app.
For example,
www.john.comwill display the content fromjohn.mysite.com.The issue you are seeing, where both
john.comandwww.john.comare leading to a 404 error, whilejohn.mysite.comis correctly displaying John's profile, could be from DNS misconfiguration, propagation delays, or the domain not being correctly added to your Vercel project.DNS Issues:
john.compointing to76.76.21.21should be correct if that is the IP address provided by Vercel for your deployment. However, Vercel generally recommends using anALIASorANAMErecord for root domains instead of anArecord if your DNS provider supports it.wwwis pointing tojohn.mysite.com, which might be incorrect ifwww.john.comis supposed to point to a Vercel deployment. It should point to your Vercel deployment URL or a Vercel-provided alias.my-app.vercel.app, which would be correct if you are trying to capture all other subdomains.For
john.comusing Cloudflare, you might try the following configuration:Vercel Deployment Issues:
john.comandwww.john.comare added to your Vercel project under the "Domains" section. Vercel needs to know about these domains to route them correctly.john.comandwww.john.com. That can involve custom domain setup within your Vercel project settings.If Vercel provides an
ANAMEorALIASrecord for root domains, use that instead of anArecord forjohn.com.john.comandwww.john.comas custom domains. That may involve a verification step.Regarding NS Records:
The NS records you added to
john.com:That configuration appears incorrect because you are setting NS records for
mysite.comwithin the DNS configuration forjohn.com. NS records are intended to delegate DNS management for a domain to another server, and should be used at the registrar level, not in the domain's DNS configuration. Ifjohn.comis using Cloudflare, it should retain Cloudflare's NS records.mysite.comfrom thejohn.comDNS settings.digornslookup, or online services like DNS Checker, to verify that your DNS records are propagating correctly.