Question

How to allow users to add their own custom domains?

I am using Next.js and I want to give my users the ability to add their own custom domains. For example, my app is hosted on DigitalOcean with domain ‘https://app.com’ and the user, say John, page is ‘https://app.com/john’ Now I want my user,John, to be able to add his own domain ‘www.john.com’ so that it display ‘https://app.com/john’ site.

I am new to networking so I am having trouble coming up with a viable solution.

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello,

What you could do is to add a catch-all Nginx server block or an Apache Vhost in case that you are using Apache.

  • For Nginx, it would look like this:
   server_name _;
  • For Apache you just create a virtual host without specifying ServerName

That way all unmapped domains will serve the content of this virtual host/server block.

After that, your clients would only have to add an A record to point to your Droplet’s IP address as per the instructions here:

https://docs.digitalocean.com/products/networking/dns/how-to/manage-records/

If they wanted to use an SSL certificate, you could tell them that they could do this by using Cloudflare with their Flexible SSL certificate.

Then you can handle the rest of the logic on the application level.

I have done a similar thing with the DevBlog here, which allows people to have a blog with their own domain name:

https://devdojo.com/devblog

Hope that this helps! Regards, Bobby