Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am building a small service where users will be assigned a subdomain such as:

I know that I can set up a wildcard vhost and using some configuration regex, serve the files like so:        ===> /var/www/myusername   ===> /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?

share|improve this question
A simple CNAME from their domain to yours would work perfectly fine, the problem arises when you start using SSL, you don't indicate if that's a requirement or not. If you're users are logging in it probably should be :) – Brent Pabst Dec 10 '12 at 1:49

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.

share|improve this answer
This is what heroku, amazon ELB, etc., do. It works well. – Michael Hampton Dec 10 '12 at 1:53
@MichaelHampton Agreed, it totally depends on the environment and what you have at your disposal as well. SSL termination does get a bit tricky if you can't afford the mega mega certs. – Brent Pabst Dec 10 '12 at 1:55
Thanks for your answer. I would prefer to not have clients set the A record to my IP address to maintain flexibility. In such a case, how do I deal with naked domains ( should point to – F21 Dec 10 '12 at 3:51
The suggestion above does not have clients specifying an A record against your IP. It uses a CNAME instead. You might want to re-read the answer as so far it seems to cover everything you are looking for. – Brent Pabst Dec 10 '12 at 12:37
From my understanding, do you mean to have a CNAME on the root domain? This seem to cause other problems, because CNAMEs on a root domain cannot exist with other records, which means records for things like mx, txt, etc can break. – F21 Dec 18 '12 at 5:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.