While I\'ve done this on my VPS, I\'ve never done this for a heroku application, and now I have to do it for a fairly large company so I really want a simple list of bullet-
In your registrars host records you want to set the @
to the redirect to the www.foobaryfoobs.com and the www
record to the CNAME of warm-chamber-1882.herokuapp.com
, this is because Heroku may change the IP address associated with that hostname and if you have the ip in your registrar you would also have to update. Using a CNAME ties that url to the ip so when Heroku updates the ip your site is still up. As long as you don't touch your MX records your email will be fine.
To protect again *.foobaryfoobs.com
issues they warn about you can also setup a host record for exactly that and make it a CNAME as well pointing at warm-chamber-1882.herokuapp.com
.
As far as setting up the SSL you can look at this article, that should get you setup.
$ heroku domains:add www.foobaryfoobs.com
How does this work? Does it update some configuration file somewhere that I need to add to the repository and then push up to heroku?
I dont know exactly how does it works internally but this command is equivalent of adding ServerName
in apache config file, without this when request comes to www.foobaryfoobs.com
it will be forwarded to heroku because of dns
but heroku fail to determine your app. You will see the below image.
That's why they need your domain so they know which apps belongs to which domains. They also need it for domain precedence purpose. No changes are required in your code as long as you are okay to allow your user to access Heroku subdomain ie warm-chamber-1882.herokuapp.com
. If you dont want user to access heroku subdomain you have to pass 301
http status so it will be redirected to your actual domain i.e www.foobaryfoobs.com
. For this you have add this in your application controller
before_action :forward_to_domain_if_heroku_subdomain
private
def forward_to_domain_if_heroku_subdomain
if request.host == 'warm-chamber-1882.herokuapp.com'
redirect_to "http://www.foobaryfoobs.com" , status: 301
end
end
Are there any caveats or best practices here? What other domains should I add? heroku domains:add *.foobaryfoobs.com, for example?
if you ONLY want to use www.foobaryfoobs.com
as your domain, this command is suffice ie
heroku domains:add www.foobaryfoobs.com
If you want to assign naked domain foobaryfoobs.com
then you ALSO have to run
heroku domains:add foobaryfoobs.com
If you application use subdomains like subdomain.foobaryfoobs.com
then you also have to run
heroku domains:add foobaryfoobs.com
2) Log into the registrar that created www.foobaryfoobs.com and navigate to its control panel.
To be precious, you have to do DNS management tool.
3) Update the domain's CNAME record to point at warm-chamber-1882.herokuapp.com
Yes.
Am I done for the most part? Now do I just wait?
Yes, but there are also other things.
Is there no IP related stuff?
Yes, there is no ip related stuff.
The domain has several dozen emails attached to it. As long as I don't touch the MX record, I should be fine?
Yes.
What's a root domain? Why should I add it?
if you want to accept requests from user at warm-chamber-1882.herokuapp.com
(not www. warm-chamber-1882.herokuapp.com
) then you have to add it.
Why should I care that: Some DNS hosts provide a way to get CNAME-like functionality at the zone apex using a custom record type.
ALIAS
or ANAME
type of records. (DNSimple provides it). You have to care it because from that custom-record-type it is easily to add record. They are like pre defined templates eg ALIAS
is template of A
record. 4) Update the domain's FORWARD / URL record so that foobaryfoobs.com points to www.foobaryfoobs.com
For a nooby, please explain why this is necessary.
It is necessary because www.foobaryfoobs.com
and foobaryfoobs.com
are different in a same way like images.google.com
and news.google
differs. www
is nothing special it is just a subdomain. If you dont do this, user can't use your site from foobaryfoobs.com
but can access www.foobaryfoobs.com
.
1) Is this how it should be set up?
Yes, it is correct. But if you want to allow foobaryfoobs.com
and www.foobaryfoobs.com
, you have to do something like below table. You dont require *.foobaryfoobs.com
record if your app doesn't use any subdomain except www
. It is bad practice actually to add *.foobaryfoobs.com
.
Type | Name | Content
---------------------------------------
ALIAS | foobaryfoobs.com | yoursite.herokuapp.com
CNAME | www.foobaryfoobs.com | yoursite.herokuapp.com
It’s important to make sure your DNS configuration agrees with the custom domains you’ve added to Heroku. In particular, if you have configured your DNS for *.example.com to point to example.herokuapp.com, be sure you also run heroku domains:add *.example.com. Otherwise, a malicious person could add baddomain.example.com to their Heroku app and receive traffic intended for your application.
Yes. Moreover you dont have to worry about this. If the malicious user can set subdomain at your domain then he capable to do much destruction :P. Actually, malicious user can't access your DNS management tool so you're safe.
You can also do this with an A/AAAA record.. in my opinion the better way.
Check out my answer in this thread
Heroku EU region how to setup custom domain name?
I can answer only some of this:
1) a) It updates some config stored on heroku's end related to your app. You can see that if you login to the heroku site and look at the config for your app. b) dunno c) this will let people type both "http://www.foobaryfoobs.com" and "http://foobaryfoobs.com" and for both of them to go to your app.