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 :
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.
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.