I am building a small service where users will be assigned a subdomain such as:
myusername.myservice.com
anotheruser.myservice.com
I know that I can set up a wildcard vhost and using some configuration regex, serve the files like so:
myusername.myservice.com ===> /var/www/myusername
anotherusername.myservice.com ===> /var/www/anotherusername
The problem is that I would like to allow users to alias their own domain names to their service.
I understand that for the webserver, once the user adds the domain via my web interface, I can easily create a vhost for the domain in nginx and then refresh the webserver.
The problem is that I would prefer to NOT let the users add an A record of my webserver's IP address as I would prefer to keep things flexible (when we upgrade our infrastructure to something more complex to scale).
What is the best way to achieve this?
As I mention in the comment above if you are not using SSL this is pretty simple, just have your clients setup CNAME records against your domain and it's A record. So you end up with this:
If you are running SSL there are a couple of different ways to work with this. You can't use the solution above as it will cause certificate errors on most browsers. Instead I usually end up with the same solution above, however instead of serving your content directly from that IP and domain name it instead serves a redirect page/script that forces the user to a SSL URL automatically.
The end result, the user can use their own custom domain name but the URL that is eventually returned is your domain after redirecting the user.
Like I said, there are loads of other ways to do this, but this is what I prefer.