Question

How to allow users to add their own custom domains?

Posted August 15, 2021 126 views
ApacheNode.jsDigitalOceanDNSJavaScriptNext.js

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.

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.

×
Submit an Answer
1 answer

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

by Justin Ellingwood
When using the Nginx web server, server blocks (similar to the virtual hosts in Apache) can be used to encapsulate configuration details and host more than one domain off of a single server. In this guide, we'll discuss how to configure server blocks in Nginx on an Ubuntu 16.04 server.