how to show different content based on incoming domain?
<h2>Problem</h2>

<p>I'm in over my head here, please point out if I'm trying to compare apples to bread.</p>

<p>I want to understand how people are doing this particular pattern (or set of patterns) which seems like magic to me. </p>

<blockquote>
  <p>Note: Concrete question below (answers need to be solutions to this)</p>
</blockquote>

<h2>Pattern</h2>

<h3>1. Galaxy meteor hosting</h3>

<p>In the <a href="http://galaxy-guide.meteor.com/dns.html" rel="nofollow">DNS config</a> they ask us to set a CNAME from www.customer1.com (you) to <code>galaxy-ingress.meteor.com</code>. </p>

<p>This blows my mind, how are they able to redirect multiple sites based on source domain. Many of them might be high traffic. This should be performant as well.</p>

<h3>2. Github.com Pages</h3>

<p>Just add your domain in their settings and setup a CNAME to a constant domain they give you. Done.</p>

<blockquote>
  <p>Note: I'm hazy on the details - forward to constant domain or your <code>GH pages user domain</code> like <code>user.github.io</code>, don't recall precisely.</p>
</blockquote>

<h3>3. Gitlab.com</h3>

<p>
They give you an IP to point an <code>A record</code> to though, that doesn't seem very uptime friendly to me.</p>

<p>PS: I love these guys, Git + CI + docker repo for free, I must be dreaming.</p>

<h3>4. Heroku</h3>

<ol>
<li>Add domain via command line or via their web gui.</li>
<li>Add a CNAME to your app-name.heroku</li>
</ol>

<p>This (like a few above) would be the best, you get a default <code>xyz.herokuapp.com</code> URL you can use even without a custom domain.</p>

<h3>5. surge.sh</h3>

<ol>
<li>add domain to a file called CNAME (I was dubious, initially, this would work, it's just too simple :))</li>
<li>add a CNAME to your xyz.surge.sh url</li>
</ol>

<h3>6. Modulus.io</h3>

<p>(I can keep going with this list)</p>

<h2>Concrete question</h2>

<p>Setup that I'd like to have based on above</p>

<ol>
<li><ul>
<li>When www.website1.com has a CNAME to ingress.yourwebsite.com, show content related to their site</li>
<li>When www.website2.com has a CNAME to ingress.yourwebsite.com, show content related to their site</li>
</ul></li>
<li>The URL should show www.website1.com or www.wesbite2.com not ingress.yourwebsite.com</li>
<li>Be easy to just add a new site programmatically</li>
<li>Be performant and uptime friendly</li>
<li>Implement on IaaS(Digital Ocean, AWS, etc) providers. (Even though as one answer suggests, you can use a PaaS(Heroku, Modulus, etc) provider's API, that's cheating isn't it, in the sense that one understands nothing by doing that as implementation is abstracted away with the API)</li>
</ol>

<blockquote>
  <p><strong>Performant:</strong> By this I mean that you're not doing this in an app layer if it could be done at the DNS layer.</p>
  
  <p><strong>Uptime friendly:</strong> By this I mean that if a server instance goes down, this service doesn't stop working</p>
</blockquote>

<h2>BONUS</h2>

<p>How do I make this work for website1.com and website2.com (note no <code>www.</code>)? </p>

<p>As in <code>www.website1.com</code> forwards to <code>website1.com</code> (or the other way based on your preference)</p>

<p>I want to set this up internally like google apps does, I don't want the user to do a fancy setup on their DNS like CNAME at their root etc.</p>

<h2>Technology preference</h2>

<p>Please use one of these rather than their competitors if possible. Please mention when you're making a sub-optimal choice by doing this.</p>

<p>In order:</p>

<ol>
<li>MeteorJS</li>
<li>NodeJS</li>
<li>Javascript</li>
<li>Cloudflare.com API</li>
<li>Nginx</li>
<li>Any github.com repo with high stars (say, 1k+) </li>
</ol>

<p>PS: I'm mentioning this preference not be a dou*he but to re-use what I know already.</p>

<p><strong>Possible solutions (which I'm not looking for):</strong></p>

<ul>
<li>iframes (bad SEO, etc)</li>
<li>mod_rewrite (are github and others using mod_rewrite, seems app level and kludgy)</li>
</ul>

<p><strong>Update #1 (13th July 2016)</strong></p>

<h2>What I've tried</h2>

<ol>
<li><ul>
<li>Deployed a meteorJS app to heroku with a custom domain (say xyz.com) and tried routing a.xyz.com etc programmatically, got errors like herokuapp doesn't exist at this domain. </li>
<li>read a lot about hoerku's wildcard domain but didn't help</li>
</ul></li>
<li><ul>
<li>Deployed a meteorJS app to meteor.com with a custom domain (say xyz.com) and tried routing a.xyz.com etc programmatically, got errors like meteor app doesn't exist at this domain.</li>
<li>They gave no access to DNS (the place I thought this needed to work at)</li>
<li>meteor.com free hosting has been shut down</li>
</ul></li>
<li><ul>
<li>I'm guessing this should be easier than the tangled ball of yarn I'm making this out to be.</li>
<li>If I can programmatically setup <code>CNAME</code>s (using cloudflare.com API, is this possible elsewhere?) like <code>website1.yourwebsite.com</code> then when someone hits <code>website1.yourwebsite.com</code>, I should know what content to serve based on URL (app level) then I can do a <code>301 redirect</code> to actual host? The URL changes on <code>301 redirect</code>. Dang!</li>
</ul></li>
<li><ul>
<li>just stumbled onto <a href="https://en.wikipedia.org/wiki/Virtual_hosting" rel="nofollow">https://en.wikipedia.org/wiki/Virtual_hosting</a> , reading.</li>
</ul></li>
</ol>

<p><strong>Update #2 (30th July 2016)</strong></p>

<ol start="5">
<li><ul>
<li>updated question to clarify that this needs to be implemented on an IaaS (Digital Ocean, AWS, etc). If you're using a PaaS(Heroku, Modulus, etc) provider's API, you still don't know how this pattern has been implemented, it has been abstracted away with the API.</li>
</ul></li>
</ol>