2
3 Comments

How to let users set wild card domains and root domains in my single server dynamically

I'm wondering how websites such as webflow can let user spin up wild card domains such as user.webflow.com dynamically (with SSL) and also let them point user.webflow.com to their personal domain names such as www.example.com. The website does these all dynamically . Can anyone say how it is done?
I know that you can do this by setting reverse proxy in nginx config file manually. Also one can use virtual host middlewares in server to spin up wild card domains.
However I wanted to know how it can be done dynamically in Nodejs servers.

on March 24, 2020
  1. -1

    This comment has been voted down. Click to show.

    1. 1

      I appreciate you answer.
      However I already know that subdomains can be handled using middlewares that uses logic.
      What I wanted to know is that how you can handle adding new root domain (not subdomain) dynamically (an in depth explanations). And how other SAAS is doing that thing?

      1. 1

        Aaah I see. One way you could go is to have domains being directed your way based on an A record, and have your server respond based on, as you might guess, host headers. As long as there is a single web-server responding to the incoming HTTP requests, you are free to handle it however you want to handle it.

        TCP traffic is being differentiated by the destination port, destination IP, source port and source IP. The HTTP protocol is transported over TCP, and HTTP adds additional information in the host header so that multiple domains can be ran on a single server. Hence, if you have a web server running on port 80 on a certain IP address, you can run any website on it using a single server, if you only check the host header. If you wish to support SSL you have to do a bit more work, because that is literally a wrapper around the TCP protocol. Personally I would offload this responsibility to a reverse proxy, but there are reasons this might not be viable, or secure.

        How I would handle that from a technical point is to set certain properties like logo and so on based on the host header, but have the rest of my application (routes) work as usual. This would be a pretty maintenance free way to allow customers use their own domains. Accepted hostnames and their properties could be configured with a database. In this case it would be beneficial to cache the values to allow quick request responses.

        Allowing customers to use CNAME records for their configuration requires a bit more set-up. Given a CNAME is a redirect, which looks up the IP address of a different domain name, you would require something with which you can dynamically create DNS records. See https://github.com/AnalogJ/lexicon for example. The benefit of this approach is that when you change servers, you can update the IP configuration for your customers.

      2. 1

        This comment was deleted 5 years ago