3

I have a server (Ubuntu + Apache) where we host an app where clients can create their own subdomains - i.e. basically wildcard subdomains.

We have a client that wants to point their own domain (www.client.com) at his unique subdomain (client.app.com) on our server. This should happen transparently, so that when someone types in www.client.com, the url still shows www.client.com, but everything is transparently working on client.app.com

In his DNS, should he create an A record pointing at our IP address, or a cname pointing at client.app.com?

Are there any differences in the vhost that we need to create in either case?

  • How often does your IP change, and does your client want example.com (i.e. no www.) to work? – ceejayoz Sep 25 '15 at 20:35
  • You should 301 the root domain to www. Anyway – Jacob Evans Sep 26 '15 at 4:52
4

In his DNS, should he create an A record pointing at our IP address, or a cname pointing at client.app.com?

He should use a CNAME pointing to client.app.com. There are many reasons to do this, but the best one is probably because it means fewer changes to make should the IP address of the server change: only the entry for client.app.com will need to be updated, and everything else that is CNAMEd to it will follow automatically.

Other reasons include the inability to have the same name A record as MX record, as one of the other posters mentioned; as well as the general philosophy that a host should only have a single "true name" (A record), and other records pointing to the same host should be aliases (CNAMEs). Of course, that philosophy breaks down when you have a single A record pointing to multiple IPs and multiple hosts (but it is another good argument for the client to use CNAMES: if your service becomes popular that you need to scale it by load balancing to other hosts that serve the same things, you'd want your customer to benefit from that without having to change anything). (Of course there are many ways to load balance and scale, and you could just as easily choose one that isn't tied to DNS, but that depends on your implementation.)

Are there any differences in the vhost that we need to create in either case?

Regardless of the DNS method you choose, you will need to make sure that apache is configured to accept the other names.

so that when someone types in www.client.com, the url still shows www.client.com, but everything is transparently working on client.app.com

Of course you'll want to confirm the below with a tour through the apache docs yourself, but I can think of two ways to do this:

  1. UseCanonicalName Off with ServerAlias inside each VirtualHost entry:

    UseCanonicalName Off <VirtualHost *:80> ServerName www.client.com ServerAlias client.app.com DocumentRoot /www/client </VirtualHost>

  2. Use multiple ServerName and VirtualHost entries:

    <VirtualHost *:80> ServerName www.client.com DocumentRoot /www/client </VirtualHost> <VirtualHost *:80> ServerName client.app.com DocumentRoot /www/client </VirtualHost>

Keep in mind that with either method, you might have to make sure the html and any associated scripts are doing "the right thing" to generate URLs properly for the behavior you desire.

There are also many good examples and interesting discussion here: http://httpd.apache.org/docs/2.4/vhosts/mass.html on the topic.

  • Another thing to remember about using a CNAME... You're not allowed to have any other record with the same name as a CNAME record. So if you create client.app.com as a CNAME, you cannot also have a client.app.com MX record for instance. – user313356 Sep 25 '15 at 20:56
  • > should the IP address of the server change: they will only need to update the entry for client.app.com, and everything else that is CNAMEd to it will follow automatically. - Is it not correct to state that if they use CNAME, then they will not have to make any changes if the IP address of my server changes, because the CNAME will point to client.app.com – JonoB Sep 25 '15 at 21:40
  • Ah, I misunderstood. I thought that the client owned client.app.com, in addition to www.client.com. Still, the principle holds: if the IP changes, only the single [A] record needs to be changed if using a CNAME. If they use A records, then you'll need to update all of them. For a single entry it probably doesn't matter much, but if you are scaling this up to more than one or two, only having a single entry to change can make things a lot easier in the future. – Jed Daniels Sep 25 '15 at 22:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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