Hi, am currently working on a SaaS product and i will need to create sub-domain on fly as users register on the app. I think this operation is related to the DNS provider or the hosting service, via an API for example. But i don't really know how it work. Looking for some help on this.
thanks
You wouldn't create the subdomain on the fly, you'd simply use a wildcard subdomain (*.yourwebsite.tld) and point that to your webserver.
Depending on what backend framework you are using, you'd need to ingest the subdomain as a parameter and use the value from that to find the user (or throw a 404, of course)
Hope that helps!
Yup! This is essentially what anymessage does to generate the team subdomains. Feel free to checkout the code, if you'd like a node.js example: github.com/d3sandoval/anymessage
oww.... that's interesting... i only knew about SSL wildcard certificat... this is sooo cool. Thank it solve my problem, am working with a NGINX + Gunicorn + Django Stack.. i can handle the domain name ingestion without problem... thank you for this.
Super welcome - glad it helped!
Hi Matthew,
Better to have single VM and single db running for each tenant? Or multitenant single db if that the case?
ie. Slack use subdomain with single db or multitenant db?
Wow. That was super easy solution. Thanks buddy.
But Where do I deploy my application? Will it be on main domain?
if you are using cloudflare they have rest api api.cloudflare.com
with simple http requests you can manage your dns records
this way you can have multiple servers
Ha... I had this kind of solution in mind.. thanks for this. I will check that, it seem to be more suitable concerning security.
yeah cloudflare is great, in the free package they give you tools like waf, ddos protection, cdn, js css optimization etc and your server ip is not exposed to the public because cloudflare works as reverse proxy
Hi guys,
I have a similar problem but I would like to give the option to the user use their domain as well. Is is possible? Like wix give you the opinion to use your domain for a e-commerce for example.
Any help appreciated.
hi @eblucas have you found the answer????
You can get wildstar certificates for TLS on AWS, if you want to have a secure connection while serving any subdomain.
yeah thank you, i knew about this type of certificate, i use to get them from GlobalSign.
You could easily get them for free from Let‘s Encrypt.
You have gotten lots of advice already but I feel an important part is left out - using a load balancer.
You can configure Nginx to handle this then instead of calling Cloudflare API as suggested above, just point the wildcard to Nginx.
From there, you can do whatever you want with the resulting traffic - authenticate it, redirect to another microservice - anything you want.
At Bytephase Repair Shop Software, we've executed a similar implementation where we assign each customer a unique subdomain and an independent database, facilitated by tenancyforlaravel.com/. This strategy has proven advantageous, as it offers our customers a personalized workspace, instilling a sense of ownership and nurturing trust. We take pride in the successful execution of this initiative.
More on challenges we faced bytephase.com/blog/subdomain-for-c...