Programing

Heroku 앱을 가리키는 apex 도메인 (www 없음)에 대해 DNS를 설정하려면 어떻게해야합니까?

lottogame 2020. 9. 3. 23:35
반응형

Heroku 앱을 가리키는 apex 도메인 (www 없음)에 대해 DNS를 설정하려면 어떻게해야합니까?


이미 Heroku 앱에 사용자 지정 도메인을 추가했으며 www.domain.com.

www앱을 확인 하지 않고 도메인을 설정하는 방법도 알아야합니다 .

내 현재 DNS 설정은 다음과 같습니다.

$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

example.com둘 다 www.example.com내 Heroku 앱을 올바르게 가리 키 도록 사용하는 올바른 설정은 무엇입니까 ?


(참고 : root, base, apex 도메인은 모두 동일합니다. google-foo와 같은 의미로 사용합니다.)

전통적으로 apex 도메인을 가리 키려면 서버의 IP를 가리키는 A 레코드를 사용합니다. 이 솔루션은 확장되지 않으며 Heroku와 같은 클라우드 플랫폼에서 실행 가능하지 않습니다. 여기에서 자주 변경되는 여러 백엔드가 요청에 응답해야합니다.

하위 도메인 (예 :)의 경우를 www.example.com가리키는 CNAME 레코드를 사용할 수 있습니다 your-app-name.herokuapp.com. 이후부터 Heroku는 동적 A 레코드를 관리하여 your-app-name.herokuapp.com항상 최신 상태를 유지합니다. 안타깝게도 DNS 사양은 zone apex (기본 도메인)에서 CNAME 레코드를 허용하지 않습니다. (예를 들어 MX 레코드는 CNAME이 먼저 대상에 이어 지므로 중단됩니다.)

루트 도메인으로 돌아가서 간단하고 일반적인 솔루션은 전혀 사용하지 않는 것입니다. 대체 조치로 일부 DNS 공급자는 HTTP 리디렉션 설정을 제공합니다. 이 경우 example.comHTTP 리디렉션이 되도록 설정하십시오 www.example.com.

일부 DNS 공급자는 zone apex에서 CNAME과 유사한 동작을 허용하는 사용자 지정 솔루션을 제공합니다. 제가 아는 한 DNSimple의 ALIAS 레코드DNS Made Easy의 ANAME 레코드가 있습니다 . 둘 다 비슷하게 작동합니다.

이를 사용하여 레코드를 다음과 같이 설정할 수 있습니다 (zonefile 표기법을 사용하여 웹 사용자 인터페이스에서이 작업을 수행 할 수도 있음).

@   IN ALIAS your-app-name.herokuapp.com.
www IN CNAME your-app-name.herokuapp.com.

기억 @여기하는 루트 도메인에 대한 속기 ( example.com). 또한 영역 파일과 일부 웹 사용자 인터페이스 모두에서 후행 점이 중요합니다.

또한보십시오:

비고 :

  • 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:

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.

참고URL : https://stackoverflow.com/questions/16022324/how-do-i-set-up-dns-for-an-apex-domain-no-www-pointing-to-a-heroku-app

반응형