0

My question is similar to this : Domain masking/pointing to a directory of a web application?.

I just want to clarify, is there any other approach? And which one is better?

I’m using laravel, nginx, mongodb, (and bind to simulate DNS configuration).

Say I have web application in mydomain.com, which every users can create their own page and get subdomain and add custom domain to it.

e.g. customdomain.me forwarded to mypage.domain.com

This process should be done automatically when user submit new custom domain (user can add more than 1 custom domain to 1 subdomain).

What I’ve done is setting DNS wildcard to point all subdomains to mydomain.com with Bind and configure nginx.conf file using server_name _; which will catch all request. Then I create script in php using laravel to open page correctly for each subdomains.

Now I want to automate domain masking which the user only need (after point their domain to my IP first) to fill out their custom domain and subdomain in a form.

So far, I have 2 approaches :

  1. Using proxy_pass in nginx

    server {
        listen 80;
        server_name customdomain.me;
    
        location / {
            proxy_pass http://rizky.domain.com;
            proxy_set_header Host rizky.domain.com;
        }
    }
    

    This approach is not good, I think, in my scenario because I have to add new block server for every custom domain (or at least for every user) and reload nginx in every changes which is hard to do if the web app already live.

  2. Fully use script to forward custom domain to subdomain

    This second approach, I store custom domain - subdomain pair in database (mongodb) then I use laravel route to forward custom domain to subdomain and serve the correct page.

    This second approach is better I think, but when the number of users grow, I'm not sure if this approach still reliable

I repeat my point, is there any better approach to forward domain with masking automatically for this kind of scenario?

If my question is not good or off topic, I will delete it.

Thanks.

  • You could take a look at https://gist.github.com/mariocesar/8186668 which allows dynamic virtual hosts. Which only requires you to create the directory with the user's sub domain and it'll work. – Niels Jul 30 '18 at 09:44
  • I'm not quite understanding the requirement. You want your visitors to create an account on your site, which gives them something like `username.yourdomain.com`? And then you also want them to be able to point their own DNS to your site, so `example.com` would become an alias for `username.yourdomain.com`? Then in a nutshell: your server simply accepts any and all requests, regardless of requested domain name (i.e. no `server_name`, or a catch-all wildcard `server_name`), and you figure out what content to display entirely inside PHP from the request headers. – deceze Jul 30 '18 at 09:48
  • Sorry if not clear enough, yes visitor can create account to get subdomain and add custom domain, my web app use wildcard dns to resolve all subdomain to my root domain and laravel to route subdomain to the correct page (all subdomain have 1 php file to serve with correct name passed to that file). My requirement is users point their custom domain to my IP and submit to my web app, so my web app can display correct name (instead of my web app's home page) when users go to their custom domain. Is it more clear now? – rizkyagung Jul 30 '18 at 10:33

0 Answers0