Hi all,
This is a problem I've never properly tackled before, but a couple of projects I have on the cards would definitely benefit from this feature. Can't find much good information out there about how to do this!
Anybody have some insights on what basic steps might look like? Or is there a service that helps?
Thanks guys!
I used caddy server to achieve that. Feel free to reach me if you need any help in configuring it :) https://www.indiehackers.com/post/generating-ssl-certs-on-demand-with-caddy-server-69ad07a3fb
My guess would be:
1 - Have the user CNAME the domain to your server (or sell them the domain and do this yourself)
2 - Have those domains on a database table mapped to a user
3 - When you get a request look at that table and find out what user it is, if the domain is not your main domain (or you might abstract this from your application by doing it on the webserver, maybe openresty with lua plugin calling on a API, and setting a header with the user ID)
4 - Do your stuff
Step 3 would probably need to be heavily cached or you would probably rip your server a new one
Yeah, that's my general vibe for how to do it too - but wondering if there's some complexities I'm not thinking about. Cacheing definitely a good call.
The hard part is automatic HTTPS. Although it's getting easier. Like @sivaram636 mentioned, the Caddy webserver does a lot of the heavy lifting for you.
Just saw this on Betalist
https://app.margashield.com/?ref=betalist
Customer adds CNAME dns pojnting to any record you control.
Do NOT give them an IP for an A record, you will regret it if you ever move server. CNAME gives you update control.
Nginx proxy server, with letsencrypt installed.
Container recommended if you are docker/kubernetes based, but cloud/dedicated server can work too.
Shared filesystem of some sort between nginx config folder and your core signup/member system.
User adds their custom domain, nginx config created, letsencrypt ssl generated, proxy reloaded.
Few hours to few days work depending on system architecture and experience in these things, simple and reliable once running.
if you don't yet have hosting, Netlify supports this via API. you can send new domains to attach to an existing site and have SSL automatically from LetsEncrypt. this would be front-end only. on the back, like others mention, it'd be a matter of looking up the domain in the request then branching into whatever is needed.
That's a shout. Is there a limit? I remember Heroku could do this but I believe had a limit.
Netlify told me it was unlimited but that was well over a year ago, imagine that's still the case but maybe safe to double check if you go that route.
I never developed some projects that required such feature because it seems complicated.
I would love to see a service (api) that can do it all the flow easily!!
If you're using Ngnix then a simple solution would be to sync a config for each of your users. You would have a form that saves the domain to you DB and when that form is submitted you also sync the Nginx config for the domain. Easy to understand and easy to maintain.
For auto SSL check out https://certbot.eff.org/
Our users have unique subdomains, which they can then use a CNAME with. On small / mvp projects we blindly assume a request coming in on a domain is legit, look up a paired subdomain, then route / fail accordingly. As a project grows or leaves mvp we start verifying domains before they'll route.
This was just published in PH few days ago:
https://www.producthunt.com/posts/qloaked
For a system like this:
DNS Server (to be used for domain name resolution)
Web Server integration (to be used for domain forwarding)
Application (to be set up for domain-specific response)
The user updates the domain's name servers to ns1.example.com. Your name server resolves this domain and redirects it to the application server.
Your web server checks whether an incoming request (domain name) exists. Then it redirects to the application.
The application responds by domain name.
https://emlakpro.net this application is also used in this.
Having an entire nameserver is overkill. Unless you need to control all subdomains too. Just have them point A CNAME record at your domain and then make sure your application knows how to handle that.
Thanks for that mate! Why does the DNS Server and Web Server have to be separated? Can't a single server receive the domain name and then check whether it exists?
The web server cannot perform domain resolution. So for example.com you need a system that will analyze A-AAAA-NS-MX records. They cannot make the web server.
The request is performed as follows.
The user creates the request to enter example.com,
DNS Server example.com analyzes and redirects to the application server,
The web server receives a response from the application and sends it back.
You must enter records for each domain name on the Web server to avoid load on the application side. You can do this with api.