Problem
I'm in over my head here, please point out if I'm trying to compare apples to bread.
I want to understand how people are doing this particular pattern (or set of patterns) which seems like magic to me.
Note: Concrete question below (answers need to be solutions to this)
Pattern
1. Galaxy meteor hosting
In the DNS config they ask us to set a CNAME from www.customer1.com (you) to galaxy-ingress.meteor.com
.
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.
2. Github.com Pages
Just add your domain in their settings and setup a CNAME to a constant domain they give you. Done.
Note: I'm hazy on the details - forward to constant domain or your
GH pages user domain
likeuser.github.io
, don't recall precisely.
3. Gitlab.com
They give you an IP to point an A record
to though, that doesn't seem very uptime friendly to me.
PS: I love these guys, Git + CI + docker repo for free, I must be dreaming.
4. Heroku
- Add domain via command line or via their web gui.
- Add a CNAME to your app-name.heroku
This (like a few above) would be the best, you get a default xyz.herokuapp.com
URL you can use even without a custom domain.
5. surge.sh
- add domain to a file called CNAME (I was dubious, initially, this would work, it's just too simple :))
- add a CNAME to your xyz.surge.sh url
6. Modulus.io
(I can keep going with this list)
Concrete question
Setup that I'd like to have based on above
- When www.website1.com has a CNAME to ingress.yourwebsite.com, show content related to their site
- When www.website2.com has a CNAME to ingress.yourwebsite.com, show content related to their site
- The URL should show www.website1.com or www.wesbite2.com not ingress.yourwebsite.com
- Be easy to just add a new site programmatically
- Be performant and uptime friendly
- 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)
Performant: By this I mean that you're not doing this in an app layer if it could be done at the DNS layer.
Uptime friendly: By this I mean that if a server instance goes down, this service doesn't stop working
BONUS
How do I make this work for website1.com and website2.com (note no www.
)?
As in www.website1.com
forwards to website1.com
(or the other way based on your preference)
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.
Technology preference
Please use one of these rather than their competitors if possible. Please mention when you're making a sub-optimal choice by doing this.
In order:
- MeteorJS
- NodeJS
- Javascript
- Cloudflare.com API
- Nginx
- Any github.com repo with high stars (say, 1k+)
PS: I'm mentioning this preference not be a dou*he but to re-use what I know already.
Possible solutions (which I'm not looking for):
- iframes (bad SEO, etc)
- mod_rewrite (are github and others using mod_rewrite, seems app level and kludgy)
Update #1 (13th July 2016)
What I've tried
- 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.
- read a lot about hoerku's wildcard domain but didn't help
- 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.
- They gave no access to DNS (the place I thought this needed to work at)
- meteor.com free hosting has been shut down
- I'm guessing this should be easier than the tangled ball of yarn I'm making this out to be.
- If I can programmatically setup
CNAME
s (using cloudflare.com API, is this possible elsewhere?) likewebsite1.yourwebsite.com
then when someone hitswebsite1.yourwebsite.com
, I should know what content to serve based on URL (app level) then I can do a301 redirect
to actual host? The URL changes on301 redirect
. Dang!
- just stumbled onto https://en.wikipedia.org/wiki/Virtual_hosting , reading.
Update #2 (30th July 2016)
- 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.