views:

3245

answers:

5

We are hosting many web applications for our customers. As is obvious they want to use their own domains to refer to those applications, usually they want that any user that either type http://www.customer1.com or http://customer1.com goes to their web application.

The situation we are facing is that we need to have the flexibility to change IP addresses in the near future. And we don't want to relay on the customer doing the A record change or their domains. So we thought that using CNAMES will work, but as we find out CNAMEs will not work for the root domain.

Basically:

customer1.com IN CNAME customer1.mycompanydomain.com //this is invalid as the RFC
www.customer1.com IN CNAME customer1.mycompanydomain.com //this is valid and will work

We want to be able to change the IP address of customer1.mycompanydomain.com or the A record and our customers will follow this record which we have control over.

in our DNS it will look like:

customer1.mycompanydomain.com IN A 5.5.5.1

any ideas?

+1  A: 

My company does the same thing for a number of customers where we host a web site for them although in our case it's xyz.company.com rather than www.company.com. We do get them to set the A record on xyz.company.com to point to an IP address we allocate them.

As to how you could cope with a change in IP address I don't think there is a perfect solution. Some ideas are:

  • Use a NAT or IP load balancer and give your customers an IP address belonging to it. If the IP address of the web server needs to change you could make an update on the NAT or load balancer,

  • Offer a DNS hosting service as well and get your customers to host their domain with you so that you'd be in a position to update the A records,

  • Get your customers to set their A record up to one main web server and use a HTTP redirect for each customer's web requests.

sipwiz
+1  A: 

Sipwiz is correct the only way to do this properly is the HTTP and DNS hybrid approach. My registrar is a re-seller for Tucows and they offer root domain forwarding as a free value added service.

If your domain is blah.com they will ask you where you would like the domain forwarded to, and you type in www.blah.com. They assign the A record to their apache server and automaticly add blah.com as a DNS vhost. The vhost responds with an HTTP 302 error redirecting them to the proper URL. It's simple to script/setup and can be handled by low end would otherwise be scrapped hardware.

Run the following command for an example: curl -v eclecticengineers.com

MrEvil
A: 

Thanks to both sipwiz and MrEvil. We develop a php script that will parse the URL that the user enters and paste www to the top of it. (e.g. if the customer enters readytocloud.com, then it will redirect to www.readytocloud.com). So our customer point their root (e.g. customer1.com to A record where our webredirector is) and then www cname to the real A manage by us.

Below the code in case you are interested for future us.

<?php
$url = strtolower($_SERVER["HTTP_HOST"]);

if(strpos($url, "//") !== false) { // remove http://
  $url = substr($url, strpos($url, "//") + 2);
}

$urlPagePath = "";
if(strpos($url, "/") !== false) { // store post-domain page path to append later
  $urlPagePath = substr($url, strpos($url, "/"));
  $url = substr($url, 0, strpos($url,"/"));
}


$urlLast = substr($url, strrpos($url, "."));
$url = substr($url, 0, strrpos($url, "."));


if(strpos($url, ".") !== false) { // get rid of subdomain(s)
  $url = substr($url, strrpos($url, ".") + 1);
}


$url = "http://www." . $url . $urlLast . $urlPagePath;

header( "Location:{$url}");
?>
Geo
A: 

For the record, cname'ing a root record is not against RFC, just has a few limitations. See http://www.faqs.org/rfcs/rfc1034.html section '3.6.2. Aliases and canonical names'.

A: 

I see readytocloud.com is hosted on Apache 2.2.

There is a much simpler and more efficient way to redirect the non-www site to the www site in Apache.

Add the following rewrite rules to the Apache configs (either inside the virtual host or outside. It doesn't matter):

RewriteCond %{HTTP_HOST} ^readytocloud.com [NC] RewriteRule ^/$ h t t p://www.readytocloud.com/ [R=301,L]

Or, the following rewrite rules if you want a 1-to-1 mapping of URLs from the non-www site to the www site:

RewriteCond %{HTTP_HOST} ^readytocloud.com [NC] RewriteRule (.*) h t t p://www.readytocloud.com$1 [R=301,L]

Note, the mod_rewrite module needs to be loaded for this to work. Luckily readytocloud.com is runing on a CentOS box, which by default loads mod_rewrite.

We have a client server running Apache 2.2 with just under 3,000 domains and nearly 4,000 redirects, however, the load on the server hover around 0.10 - 0.20.

Note: Change "h t t p' to 'http' in the rewrite rules because this site has a restriction of "sorry, new users can only post a maximum of one hyperlink".