dynamically generate subdomains with a user’s registry

I don’t know much about angular, but your general approach should be the following:

  • Create the wildcard DNS record for your domain and point it to your server;

  • Create the nginx server block for the *.domain.com and get the user name from the incoming request. This can be done several ways, for example

    map $http_host $username {
        ~^(.*)\.domain\.com$    $1;
    }
    
    server {
        ...
        server_name *.domain.com;
        ...
    }
    

    or

    server {
        ...
        server_name ~^(?<username>.*)\.domain\.com;
        ...
    }
    

    In both cases the user name would be accessible via the $username nginx variable.

  • Pass username to your angular app. As I said, I don’t know how the angular apps are written, but if you tell me how some parameter could be passed to such an application (via query argument, HTTP header, URI route etc.), I will suggest you how to do it with the nginx config.

I don’t know should it be a new angular application or this functionality could be added to your main app (I think you can do it both ways), but what I’m sure of is that you don’t need to dynamically generate subdomains or create directories for users.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top