Mapping Custom Domains to Wildcard Sub-domains - next.js

I'm creating a NextJS project which makes use of wildcard subdomains.
I've set up wildcard subdomains on Vercel, so now each wildcard subdomain points to my main NextJS installation. Within the NextJS app, I'm reading the subdomain name and serving the content accordingly.
So, let's say my wildcard entry is *.example.com
Now, all subdomains, such as roman.example.com, greek.example.com, are being served correctly with content coming from my database correctly.
The challenge I'm facing is to map custom domains to each of these subdomains.
For example, if I want myroman.com to map to roman.example.com and mygreek.com to map to greek.example.com, I'm unable to get it to work.
Say, for example, if in myroman.com DNS records, if I add a CNAME record pointing to roman.example.com, and then if I visit myroman.com, it shows me 404 deployments not found error. Note that something like myroman.com is a customer's site, and the only thing I can ask a customer is to add a DNS record to map it to a sub-domain. I cannot take control of their domain or anything like that.
You would see that companies like substack offer such custom domain mapping to their customers.
Can you suggest what's the best way to achieve this? I'm okay to change host or anything to make this work.

Thanks to Krabs, we can host multiple websites inside of our Next.js instance and serve them separately depending on the domain that the user is browsing
https://micheleriva.github.io/krabs/docs/intro/
I hope this is what you are looking for!

Related

concerns about required A records for setting up Firebase Dynamic Links with a custom subdomain

In setting up our own subdomain to handle Firebase Dynamic Links using these docs, the wizard says to put the A records at example.com in our DNS. I'm getting pushback from our network administrators who are wary of creating an A record at the root of our domain, which is a large e-commerce web site.
A couple of concerns/questions about this:
The IP addresses required (151.101.1.195 and 151.101.65.195) point to non-Google servers (looks like Fastly), which is a bit alarming - it seems strange that Google would outsource their deep link hosting.
We don't want all of our e-commerce traffic (coming through example.com) to be subject to these A records. Is it possible to put the A records at link.example.com instead?
The Firebase documentation on using a custom domain for dynamic links has this note:
To use a custom domain for Dynamic Links, the domain must point to Firebase Hosting. If you have a domain you want to use with Dynamic Links and the domain points to a different host, you can either move to Firebase Hosting or create a subdomain hosted by Firebase, which you can use for Dynamic Links.
So you can indeed use a subdomain for the dynamic links. In that case, just set up the subdomain in Firebase hosting. You'll need the same TXT record as normal, to prove that you have access to the domain, but then just map the subdomain (e.g. links) for the A record.
Here is the answer I received from Firebase support about these my two concerns/questions:
Regarding Fastly, Firebase uses this subprocessor to deliver content and managed services on Firebase Hosting. For more details you could check the list of Subprocessors used by Firebase on this doc.
It's possible to use a subdomain as your Firebase project's FDL domain. You'd need to create a subdomain (link.example.com) on your domain's DNS provider and connect it to Firebase Hosting. You could check out this guide for more details.

Domain Name Servers set by two different hosts

Can I add multiple hosts name servers for the same domain?
Let's say I have a domain on Godaddy, can I set WordPress Name Servers AND AWS Name Servers on it?
Specific Scenario:
I have static pages on Wordpress
I have django application behind an ELB on AWS
I want both to be on new.example
I want the static pages served by new.example
I want app.new.example to serve the django application.
Can I add multiple hosts name servers for the same domain?
Technically, yes (all domain names have typically at least two nameservers), but in the context of your question, no, as it would not operate the way you think it does.
You delegate your domain name to a set of nameservers that have all the content of the zone. It does not matter where the content pointed by records in the zone are handled, it can be elsewhere.
You will have to choose one company to provide DNS service to you, and then through their web panel or equivalent you will point new.example to point to your static pages on WordPress, and app.new.example to point to ELB on AWS.

Redirect Domain X to site on Domain Y, but make it look like the site is on Domain X

I'm not sure if this is possible. Not too familiar with Mod Rewrite.
I have domain1.tld registered on a hosting company and then I'm hosting a website on domain2.tld. I have forwarded domain1.tld and masked it. It works fine. Now I want domain2.tld to also show domain1.tld if I type it into the address bar.
It's running a WordPress site, so all my links are domain2.tld/link, but it only displays domain1.tld and my favicon also is gone. Is there a way I can get around this or would it be better to set up a hosting account where domain1.tld is registered, move the website there and redirect domain2.tld to domain1.tld. This would definately be the quickest and easiest way. I cannot point domain1.tld to domain2.tld or transfer it as the host does not support this TLD.
I assume your account at domain2.net does not support additional "Addon" or "Parked" domains (possible with some cPanel or maybe Plesk accounts)? I'm not sure whether a restriction on the TLD would apply here, since you're not "transferring" anything, just changing NAMESERVER or A records?
would it be better to set up a hosting account where domain1.tld is registered, move the website there and redirect domain2.tld to domain1.tld
Otherwise... Yes, that would certainly be a preferable solution.
If not, you are still going to need some kind of hosting account at domain1.tld from which you can forward requests (as a reverse proxy) to domain2.tld. Using "masked" (or "framed") forwarding is not a particularly good solution, as you have found. However, acting as a reverse proxy would require some configuration at domain1.tld, and depending on the next bit (see below) this might require more configuration.
so all my links are domain2.tld/link
If you want your site to be displayed at domain1.tld then this is something you would need to resolve. Can you make the links root-relative? Does WordPress need to know the domain/host on which it is running?
It is possible that the reverse proxy can handle this (ie. changing the link URLs in the HTML), but this requires more configuration. Or, you can roll your own proxy server.
But this all involves you having a hosting account (with some capability) anyway, so you might as well host your site there to begin with?

Firebase Custom Domain Name

I’m having a lot of trouble configuring my custom domain. Currently, if you go to my site www.mydomain.com it redirects to the default somecrazyname.firebase.com. In my google domains, I just have both www.mydomain.com and mydomain.com redirecting to the mycrazyname.firebase.com just for the sake of having something live until I can figure this out. My question is, how do I make it so when you go to www.mydomain.com it stays on www.mydomain.com while showing my amazing content and not somecrazyname.firebase.com.
Everything is configured correctly with firebase as far as my custom url goes(verification, etc.). However, the url firebase gave me is https mydomain.com (where if you go there it says the site can't be displayed) where my domain on Google domains is http. I've tried to configure redirects within my firebase json as well as my synthetic records in Google domains, but have had no such luck and am out of ideas. I've also looked at the firebase hosting custom domains documentation and am just not getting it.
Here are some visuals....
My redirects as seen on Google domains
I'm sure it's just a matter of putting things in the right places, but I have been trying this for a few hours and have not had any luck.
It was the synthetic records that was causing the issue for me. I was using CName records which, by the direction of the firebase support team is good only for subdomain redirects. Below is part of an email from the firebase support team. This is her answer to this as well as some helpful explanations.
Firebase uses TXT records for the verification of your custom domain.
On the other hand, CNAME and/or A records are used for redirection. Please take note of the following:
If you have a subdomain, CNAME records are recommended
Note that the host name with "*" indicates a wildcard. Any subdomains typed before your custom domain will redirect you to your
hosted custom domain.
Otherwise, if you have a custom domain without a subdomain, A records are recommended.
Note that adding both A records will increase redirection performance
Also, kindly remove other A records that are not from Firebase to prevent redirection issues
That's about it. Firebase Static Hosting only needs three records
(TXT, CNAME, A). Other than that, you wouldn't have the need to
implement domain forwarding such as your Synthetic records. Moving
forward though, I would suggest you to remove your Synthetic records
and add the A records I have provided on my previous email.
You should NOT be using a redirect (301 or 302) record for your domain. Instead, you should set a CNAME record. Here's how to fix it:
Delete the second redirect in your screenshot (the one that redirects to Firebase).
Go to the DNS tab of your Google Domains control panel, scroll down to the Custom resource records section, and add a record that looks like this:
www | CNAME | _____ | portfolio-6f15b.firebaseapp.com

How do I allow a user to use their own domain name for a hosted service?

I am working on an ASP.NET MVC web app that allows people to publish content, but other than publish the content to a remote server, I want to allow people to use their domain name directly. For example, the user "Tom" can have his domain name TomSite.com point to http://www.mywebapp.com/user/tom, but the sub path will also be mapped. For example, TomSite.com/path will be mapped to www.mywebapp.com/user/tom/path, and this is transparent to the web visitor. The visitor will never see "mywebapp.com" anywhere on TomSite.com.
I think Smugmug.com provides such service, to allow people to use their own domain name for the photo portfolio. I want to achieve the same result.
How can I do this? Thanks!
This require multiple steps.
First you have to find out how your users will configure their domain to have a CNAME record for you site. You can archieve this in a number of ways where the best is education. Making partnerships with hosting providers requires a great deal of volume.
In IIS this will require you to either add each host name manually (however this could also be archieved through scripting) or have a dedicated IP address only for you site.
There is also a need for the domain to be associated with an account. The user has to add this themselves and you would probably add a check in the interface which confirms the domain is pointed at your server. The code for this would look like (remember to include the System.Net namespace).
if (Dns.GetHostEntry("www.user.example.com").HostName == "www.example.com")
{
// www.user.example.com is a CNAME for www.example.com
}
In you ASP.NET MVC project you need to implement routes for this particular purpose. Create a custom class inheriting from Route which also takes the domain into account.
Smugmug (who you mentioned) get their users to setup a CNAME record that will alias the url for the user's personal photo section. For most users this will probably require them contacting their host or looking up help files in order to get it all setup.
So, while www.tomsite.com could transparently serve up pages hosted at www.mywebapp.com the users will have to put some kind of effort in. To make it a completely seamless you will need some kind of arrangement with the users web host (Smugmug appear to have such an arrangement with GoDaddy).
I doubt you will be able to setup such integration with all the web hosts out there, so the only complete solution would be to host the websites of your users yourself (I do not know enough about your wider situation to determine if that is a reasonable solution).
Note: setting up an alias on your own web server (aka url rewriting) will not work, unless you host their site yourself, as obviously people fetching from your user's domain will not arrive at your server in the first place.
Have each customer's friendlyname pointed at the external ip address of your webserver.
Use IIS to resolve the friendlyname specified in the host header request to the logical website you want delivered to that friendlyname. IIS will happily map both a website and a virtual folder to the same folder in the file system. Create a website for each customer. Then bind that website to the customer's friendlyname.
Remember to map the default website only to your own friendlyname(s). If you leave it in promiscuous mode (mapped to "*") results will be unpredictable.
To set host header mapping
Select Default Web Site under the Sites node. In the Actions pane at top right click on Bindings... to open the Site Bindings dialog. There will be a list of bindings, probably containing a single entry that says http * 80. Select this and click the Edit... button. Set Host name to your own friendlyname.
Run IIS7 Manager and for each customer site create a website under the Sites node. Set both file path and host header binding while you are creating each web site. Obviously the host header binding (host name) should be that customer's friendlyname.
Just make a new record in your webserver setting tomsite.com directly to your mywebapp.com/user/tom/ path ?
See it like an alias :)
Ofcourse, since you're asp.net/windows based, i think you'll have to digg deep into IIS to automate this kind of stuff. If you were on apache it would be adding 3 simple lines to httpd.conf.

Resources