I'm trying to understand how web services which have you setup CNAME records on your domain pointing to their servers work.
For example, following the instructions on LaunchRock (http://support.launchrock.com/knowledgebase/articles/36694-creating-your-cname-record-godaddy), I create a CNAME record as
signup.mysite.com
with the value
sites.launchrock.com
I understand that folks accessing signup.mysite.com would be redirected to sites.launchrock.com, but I'm trying to understand how sites.launchrock.com is configured so that it detects this incoming request and tailors the webpage appropriately for my landing page.
What software / configuration is present there that handles this properly?
I looked at this How does bit.ly allow anyone to use cname.bit.ly as their CNAME? - but this did not explain how to serve different content to different domains.
They're using what's generally referred to as Name-based virtual hosting. For the most part, all of the widely-used web servers support this.
The nutshell version of how this works is that when your web browser connects to a remote webserver, in its request, it sends a "host" header, which contains the FQDN portion of the URL. So if you entered
http://foo.example.com/?q=baz
into your web browser, thehost
header would containfoo.example.com
. The web server can determine which site/application to serve depending on what host header the browser sends.The other upside of name-based virtual hosting is that it allows site owners to serve a near-infinite number of domains off of a single IP address. That situation gets a bit more complicated if SSL is involved, but I'll leave the details of that for another answer.