Custom root domain on Heroku - heroku

I have a domain, example.com, that I want to use for my rails-app that resides at example.herokuapp.com and I'm pretty confused how to go about to do this.
Heroku says
"Zone apex domains (aka "naked", "bare" or "root" domains), e.g.,
example.com, using conventional DNS A-records are not supported on
Heroku." And then they go on explaining workarounds (using ALIAS or
ANAME).
I have spent a good hour reading up on the subject (here on SO and elsewhere) but still don't get my head around this.
Are there any alternative ways or explanations on how to acomplish this for "a dummy"?

I'll take a stab at this as it's a frequent question.
Ok, so assuming you have a domain example.com and you want to use www.example.com to host your site. In traditional hosting you'd probably have a virtual server which has been assigned an IP address, in this case you would use a host record, otherwise known as an A record in DNS control panels to map www.example.com to the IP address. In this case, since you have now set www.example.com to a fixed IP address should that IP address ever change you will need to update your DNS yourself.
Also, with traditional hosting you could have example.com set to the same IP address so www.example.com and example.com would work for naked domains.
Ok, so what's a CNAME record. A CNAME record rather than mapping to an IP address maps the record to another DNS entry. So, www.example CNAME'd to example.herokuapp.com means that Heroku can and may move where example.herokuapp.com is pointing at but you don't have to update anything as you're using an CNAME record and Heroku are managing where example.herokuapp.com is pointing (which can and may be another CNAME or an IP address). The problem with CNAME records is that they CANNOT point to an IP address, which is fine for www.example.com but a problem with example.com. Heroku previously published IP addresses to be used for naked domains but problems ensued when they suffered DDOS attacks and couldn't replace those IPs with new ones as they were published IP addresses. For the new EU region, Heroku ARE NOT publishing IP addresses for use with naked domains.
What several DNS providers (DNSsimple I know is one) have done is add their own ALIAS records to their DNS servers to allow you to use CNAME's with naked domains so both www.example.com and example.com will work as now supported by Heroku. If you DNS provider does not support ALIAS records then it's worth moving the domain to a DNS provider that does support it. DNSsimple also supports redirect records so you can have www.example.com redirect to example.com at the DNS provider level and not at your application layer.

Found this:
http://blog.cloudflare.com/zone-apex-naked-domain-root-domain-cname-supp
CloudFlare provides a whole bunch of other benefits as well. I've been using them for all of my Heroku apps and I'm quite pleased to be honest.
They provide a lot value for free from my experience with them thus far.

If you look at DNS records specification you'll find no such record as ANAME.
The best way to solve this problem is:
Make CNAME entry for www subdomain to your heroku app, and CNAME record for root domain to www subdomain.
www.domain.com. 3600 IN CNAME app.herokuapp.com.
# 3600 IN CNAME www.domain.com.
P.S. It works, and do not make you waste money for mystic DNS records

Related

Pointing the root domain to Heroku

I have an app on Heroku, but I can't get the naked root domain to work.
I have a CNAME record for www.mydomain.com pointing to my app.herokuapp.com
I can't create a CNAME for mydomain.com, domain provider tells me I need to do it through an A record, that points to my IP address.
So, since Heroku won't give me that IP address, how can I proceed?
Thanks
DNS RFC (RFC1033) requires the "zone apex" (sometimes called the "root domain" or "naked domain") to be an "A Record," not a CNAME.
CloudFlare provides a feature called CNAME Flattening which essentially solves this problem for you.
Read more: https://blog.cloudflare.com/zone-apex-naked-domain-root-domain-cname-supp/

how to set up a cdn?

I just bought a cdn from ovh.ie for my website example.com
Here are the instructions. however, i am unable to set up it. Can someone guide me on how to set it up step by step?
1) Report the Backends (IP of your servers) ;
2) Declare the domain/sub-domains that you want to intergrate with the CDN ;
3) Point your domain to the CNAME created after your domain is registered;
4) Add your first cache rule.
Adding a domain on the CDN generates a CNAME with the format yourdomain.ext.web.cdn.anycast.me, you need to point the DNS of yourdomain.ext to this CNAME to activate it.
Once configured, a time delay is necessary so that all of your CDNs are operational. Otherwise, it will reach its full performance with progressive caching as set by your rules
You need to edit the DNS details for yourdomain.ext so that it points to yourdomain.ext.web.cdn.anycast.me for example.
There are typically two types of DNS records that you need to worry about, A records which point to an IP address and CNAMEs which point to a URL.
The root/apex of a domain can only point to an IP on most systems.
The root domain in your case is example.com and can only use an A record.
Subdomains can use both CNAME's and A records.
Apex A record example (example.com):
Hostname Type Target
-------- ---- ---------------------------------
# CNAME 1.1.1.1
WWW subdomain CNAME example (www.example.com):
Hostname Type Target
-------- ---- ---------------------------------
www CNAME yourdomain.ext.web.cdn.anycast.me
The advantage of using the cname is it can hold a number of IPs that can change, if you simple pointed your site at one of their IP addresses they could disable it and take your site down, so it you are given a URL always use a CNAME to it instead of an A record to an IP.
This is why many websites use WWW.example.com or subdomain.example.com.
It is worth noting that using a cname as an apex is not RFC compliant and some hosts do not allow it or offer an alternative proprietary record type to achieve this on their internal system.
Another way around this if your nameserver provider is RFC compliant is to have to apex be an A record and point to a page with a redirect to the CDN or to use a service like wwwizer.
DNS Glossary

What is CNAME exactly DNS entries of Domain Hosting

In what purpose we have to configure CNAME entr in DNS entry. Is there way possible to configure 2 domains for single hosting. IN this scenerio, how CNAME help for us.
thanks.
A Canonical Name record (abbreviated as CNAME record) is a type of resource record in the Domain Name System (DNS) used to specify that a domain name is an alias for another domain, the "canonical" domain. All information, including subdomains, IP addresses, etc., are defined by the canonical domain.
This can prove convenient when running multiple services (like an FTP server and a webserver; each running on different ports) from a single IP address. One can, for example, point ftp.example.com and www.example.com to the DNS A record for example.com, which in turn points to the IP address. Then, if the IP address ever changes, one only has to record the change in one place within the network: in the DNS A record.
CNAME records must always point to another domain name, never directly to an IP address.
More info from https://en.wikipedia.org/wiki/CNAME_record
CNAME is just an alias. I can see it being useful in cases such that you want to hand out a bunch of subdomains to each client but they all point to the same source and that source is not necessarily an IP Address because it's load balanced between a few IP Addresses. I would say it offers different levels of abstraction in this case.
There is a way to configure 2 domains for a single hosting. I am assuming by hosting you mean a server hosting. You can use nginx to achieve this.
server {
server_name example1.com;
#proxy to appropriate port etc
}
server {
server_name example2.com;
#proxy to appropriate port etc
}
Take a look at this post which probably explains a bit more in detail for the handling of two domains/subdomains.
Hope that helps.
The CNAME record is the canonical name record which is used to create an alias name to other. For an example if a user has the data on the domain files.example.com and the other user is needed to search the same content which is with files.example.com from myfiles.example.com.
Then in this case the cname record helps. so one should point the domain myfiles.example.com to files.example.com in the DNS entries.

How do I set up DNS for an apex domain (no www) pointing to a Heroku app?

I already added a custom domain to my Heroku app and it works with www.domain.com.
I need to know how to set up the domain without www to resolve to the app, too.
Here are my current DNS settings:
$TTL 86400
# IN SOA ns1.first-ns.de. postmaster.robot.first-ns.de. (
2013041500 ; serial
14400 ; refresh
1800 ; retry
604800 ; expire
86400 ) ; minimum
# IN NS robotns3.second-ns.com.
# IN NS robotns2.second-ns.de.
# IN NS ns1.first-ns.de.
# IN A 88.198.38.XXX
localhost IN A 127.0.0.1
mail IN A 88.198.38.XXX
ftp IN CNAME www
imap IN CNAME www
loopback IN CNAME localhost
pop IN CNAME www
relay IN CNAME www
smtp IN CNAME www
www IN CNAME appname.herokuapp.com.
# IN MX 10 mail
What are the correct settings to use so that both example.com and www.example.com would point correctly to my Heroku app?
(Note: root, base, apex domains are all the same thing. Using interchangeably for google-foo.)
Traditionally, to point your apex domain you'd use an A record pointing to your server's IP. This solution doesn't scale and isn't viable for a cloud platform like Heroku, where multiple and frequently changing backends are responsible for responding to requests.
For subdomains (like www.example.com) you can use CNAME records pointing to your-app-name.herokuapp.com. From there on, Heroku manages the dynamic A records behind your-app-name.herokuapp.com so that they're always up-to-date. Unfortunately, the DNS specification does not allow CNAME records on the zone apex (the base domain). (For example, MX records would break as the CNAME would be followed to its target first.)
Back to root domains, the simple and generic solution is to not use them at all. As a fallback measure, some DNS providers offer to setup an HTTP redirect for you. In that case, set it up so that example.com is an HTTP redirect to www.example.com.
Some DNS providers have come forward with custom solutions that allow CNAME-like behavior on the zone apex. To my knowledge, we have DNSimple's ALIAS record and DNS Made Easy's ANAME record; both behave similarly.
Using those, you could setup your records as (using zonefile notation, even tho you'll probably do this on their web user interface):
# IN ALIAS your-app-name.herokuapp.com.
www IN CNAME your-app-name.herokuapp.com.
Remember # here is a shorthand for the root domain (example.com). Also mind you that the trailing dots are important, both in zonefiles, and some web user interfaces.
See also:
Doing DNS right with Heroku
Avoiding Naked Domains and DNS A-records
Remarks:
Amazon's Route 53 also has an ALIAS record type, but it's somewhat limited, in that it only works to point within AWS. At the moment I would not recommend using this for a Heroku setup.
Some people confuse DNS providers with domain name registrars, as there's a bit of overlap with companies offering both. Mind you that to switch your DNS over to one of the aforementioned providers, you only need to update your nameserver records with your current domain registrar. You do not need to transfer your domain registration.
To point your apex/root/naked domain at a Heroku-hosted application, you'll need to use a DNS provider who supports CNAME-like records (often referred to as ALIAS or ANAME records). Currently Heroku recommends:
ALIAS at DNSimple
ANAME at DNS Made Easy
ANAME at easyDNS
ALIAS at PointDNS
CNAME at CloudFlare
Whichever of those you choose, your record will look like the following:
Record: ALIAS or ANAME
Name: empty or #
Target: example.com.herokudns.com.
That's all you need.
However, it's not good for SEO to have both the www version and non-www version resolve. One should point to the other as the canonical URL. How you decide to do that depends on if you're using HTTPS or not. And if you're not, you probably should be as Heroku now handles SSL certificates for you automatically and for free for all applications running on paid dynos.
If you're not using HTTPS, you can just set up a 301 Redirect record with most DNS providers pointing name www to http://example.com.
If you are using HTTPS, you'll most likely need to handle the redirection at the application level. If you want to know why, check out these short and long explanations but basically since your DNS provider or other URL forwarding service doesn't have, and shouldn't have, your SSL certificate and private key, they can't respond to HTTPS requests for your domain.
To handle the redirects at the application level, you'll need to:
Add both your apex and www host names to the Heroku application (heroku domains:add example.com and heroku domains:add www.example.com)
Set up your SSL certificates
Point your apex domain record at Heroku using an ALIAS or ANAME record as described above
Add a CNAME record with name www pointing to www.example.com.herokudns.com.
And then in your application, 301 redirect any www requests to the non-www URL (here's an example of how to do it in Django)
Also in your application, you should probably redirect any HTTP requests to HTTPS (for example, in Django set SECURE_SSL_REDIRECT to True)
Check out this post from DNSimple for more.
I am now using Google Apps (for Email) and Heroku as web server. I am using Google Apps 301 Permanent Redirect feature to redirect the naked domain to WWW.your_domain.com
You can find the step-by-step instructions here
https://stackoverflow.com/a/20115583/1440255
You are not allowed to have a CNAME record for the domain, as the CNAME is an aliasing feature that covers all data types (regardless of whether the client looks for MX, NS or SOA records). CNAMEs also always refer to a new name, not an ip-address, so there are actually two errors in the single line
# IN CNAME 88.198.38.XXX
Changing that CNAME to an A record should make it work, provided the ip-address you use is the correct one for your Heroku app.
The only correct way in DNS to make a simple domain.com name work in the browser, is to point the domain to an IP-adress with an A record.

How do you set up a custom domain with CNAME on Heroku without messing up email service?

I have a Rails app uploaded to Heroku and I'd like to use it for a custom domain name. I also have email for this domain name on 1and1 where I registered it and it's been in use and needs to remain working. I tried following this tutorial but it recommends using naked domains which Heroku is strongly discouraging. If I shouldn't use naked domains (is that better?), how do I use CNAME instead while still keeping the email functional?
You will need to add a CNAME record for each "hostname" you want to use. For example, if you want to use www.yourdomain.com you would need to add a CNAME record to your DNS server(service) that maps www -> your-app-name.heroku.com.
Your DNS servers will then direct all requests for www.yourdomain.com to DNS name you-app-name.heroku.com and Heroku's DNS handles the mapping to IP address.

Resources