0

I am working on a MEAN stack SAAS application where I provide each user with their own unique subdomain. For example, the user John Doe has the following subdomain to his name: johndoe.website.com.

Now, if John, the user, wants to map his subdomain to his own custom domain or subdomain, for instance, register.johndoe.com/registraton, he should be able to do that.

How can I accomplish this?

I am looking for steps to accomplish this using NGINX and Node js in a manner that will lead to minimal changes to our existing code base.

I have searched the internet, and I was unable to find a resource that can serve as a step-by-step guide to help me solve this problem.

I know that the solution would involve the creation of Server Blocks to handle wildcard subdomains using NGINX, but I am not sure about the exact steps that will have to be implemented to get this done.

  • 3
    This will be a tad more tricky, you'll need to dedicate the nginx to just this application, either with just single server block or with a server_name set to regex `~.`. Then nginx will process all requests no matter what the domain name is. Then just check the url in your app and check if any user has such a domain name as mapping. Ask users to add a cname mapping with value set to the full subdomain.example.com in their domain dns and everything will work. – Mat J Apr 15 '20 at 15:11
  • @MatJ: Thanks again. Much appreciated. – Manvendra Singh Apr 15 '20 at 16:39
  • No problem... Glad to help. – Mat J Apr 15 '20 at 16:55
  • @MatJ: I had a couple of follow up questions: 1. Since we want to generate subdomains on the fly, we have implemented wildcard subdomains to accomplish that. Now, if we want to provide custom domain mapping to a user, can't we ask all users to edit their DNS records by adding value = domain.website.com that would be common across all users. Later on, when a we receive a request from a custom domain, we just check the URL and respond accordingly. I would appreciate it if you can respond, please – Manvendra Singh May 17 '20 at 13:19
  • @MatJ: As you suggested here https://stackoverflow.com/questions/61226187/how-to-create-handle-subdomains-on-the-fly-using-nginx-and-node-js, in a multi-tenant setup, creation of subfolders isn't necessary. Would this change if I provide the user with custom domain mapping as well as a subdomain on my website? – Manvendra Singh May 17 '20 at 13:22

0 Answers0