developer tip

루트 도메인 CNAME 제한을 극복하는 방법?

optionbox 2020. 7. 29. 08:09
반응형

루트 도메인 CNAME 제한을 극복하는 방법?


우리는 고객을 위해 많은 웹 응용 프로그램을 호스팅하고 있습니다. 명백한 바와 같이, 그들은 자신의 도메인을 사용하여 해당 응용 프로그램을 참조하려고합니다. 일반적으로 웹 응용 프로그램을 입력 http://www.customer1.example하거나 사용하는 모든 사용자를 원합니다 http://customer1.example.

우리가 직면 한 상황은 가까운 시일 내에 IP 주소를 변경할 수있는 유연성이 필요하다는 것입니다. 또한 도메인에서 A 레코드 변경을 수행하는 고객에게 의존하고 싶지 않습니다. 따라서 CNAME레코드 사용 은 효과 가 있다고 생각 했지만 CNAME루트 도메인에서는 레코드가 작동하지 않습니다.

원래:

customer1.example IN CNAME customer1.mycompanydomain.example //this is invalid as the RFC
www.customer1.example IN CNAME customer1.mycompanydomain.example //this is valid and will work

우리 customer1.mycompanydomain.exampleA레코드 의 IP 주소 또는 레코드 를 변경할 수 있기를 원하며 고객은 우리가 제어하는이 레코드를 따릅니다.

우리 DNS에서는 다음과 같이 보일 것입니다 :

customer1.mycompanydomain.example IN A 192.0.2.1

어떤 아이디어?


이 질문이 여전히 자주 발생하는 이유는 앞서 언급했듯이 누군가가 중요한 것으로 추정 한 곳에서 RFC 상태 앞에 도메인이없는 도메인 이름이 유효하지 않다고 썼기 때문입니다. 그러나 RFC를주의 깊게 읽으면 이것이 정확히 말하는 것이 아님을 알 수 있습니다. 실제로 RFC 1912 는 다음과 같이 말합니다.

CNAME과 함께하지 마십시오. 호스트 이름을 바꿀 때 사용하지만 호스트 를 제거 하고 사용자에게 알리십시오.

일부 DNS 호스트는 사용자 지정 레코드 유형을 사용하여 영역 정점 (네이 키드 도메인 이름의 루트 도메인 수준)에서 CNAME과 유사한 기능을 얻는 방법을 제공합니다. 이러한 기록에는 다음이 포함됩니다.

  • DNSimple의 별칭
  • 쉬운 DNS의 ANAME
  • easyDNS의 ANAME
  • CloudFlare의 CNAME

각 공급자마다 설정이 비슷합니다. CNAME 레코드와 마찬가지로 apex 도메인의 ALIAS 또는 ANAME 항목을 example.domain.com으로 지정하십시오. DNS 공급자에 따라 비어 있거나 @ Name 값은 영역 정점을 식별합니다.

ALIAS 또는 ANAME 또는 @ example.domain.com

DNS 공급자가 이러한 레코드 유형을 지원하지 않는 경우 해당 레코드 유형으로 전환 할 수없는 경우이를 수행해야하는 프로토콜 또는 서버 소프트웨어에 따라 어렵지 않은 하위 도메인 리디렉션을 사용해야합니다. .

나는 그것이 "아마추어 관리자"나 그러한 아이디어에 의해서만 이루어 졌다는 진술에 강력히 동의하지 않습니다. "이름과 서비스는 무엇을해야합니까?" 그런 다음 DNS 구성을 조정하여 그러한 희망을 충족시킵니다. 귀하의 주요 서비스가 웹 및 전자 메일 인 경우 CNAME을 삭제하는 것이 문제가되는 정확한 이유는 없습니다. 결국 @ domain.org보다 @ subdomain.domain.org를 선호하는 사람은 누구입니까? 프로토콜 자체를 이미 설정 한 경우 누가 "www"가 필요합니까? 루트 도메인 이름 사용이 유효하지 않다고 가정하는 것은 비논리적입니다.


CNAME의 루트 레코드는 기술적으로 RFC에 대한 것이 아니지만 권장되지 않는 방법이라는 제한이 있습니다.

일반적으로 루트 레코드에는 여러 항목이 있습니다. 이름 서버는 3 개, IP 주소는 1 개를 말합니다.

RFC 당 :

CNAME RR이 노드에 있으면 다른 데이터가 없어야합니다.

그리고 IETF 당 '일반적인 DNS 운영 및 구성 오류'문서 :

이것은 종종 경험이없는 관리자가 도메인 이름도 호스트가되도록하는 명백한 방법으로 시도됩니다. 그러나 BIND와 같은 DNS 서버는 CNAME을보고 해당 이름에 대한 다른 리소스 추가를 거부합니다. 다른 레코드는 CNAME과 공존 할 수 없으므로 NS 항목은 무시됩니다. 따라서 podunk.xx 도메인의 모든 호스트도 무시됩니다!

참고 문헌 :


그들이 어떻게 도망 치거나 어떤 부작용이 있는지 알지 못하지만 Hover.com을 사용하여 일부 도메인을 호스팅하고 있으며 최근에 도메인의 정점을 CNAME으로 설정했습니다. 그들의 DNS 편집 도구는 전혀 불평하지 않았으며, 도메인은 지정된 CNAME을 통해 행복하게 해결됩니다.

Dig가이 도메인 (mydomain.com으로 난독 화 된 실제 도메인)에 대해 표시하는 내용은 다음과 같습니다.

; <<>> DiG 9.8.3-P1 <<>> mydomain.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 2056
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;mydomain.com.          IN  A

;; ANSWER SECTION:
mydomain.com.       394 IN  CNAME   myapp.parseapp.com.
myapp.parseapp.com. 300 IN  CNAME   parseapp.com.
parseapp.com.       60  IN  A   54.243.93.102

우리 회사는 www.company.com이 아니라 xyz.company.com이지만 웹 사이트를 호스팅하는 많은 고객들에게도 같은 일을합니다. 우리는 그들이 할당 한 IP 주소를 가리 키도록 xyz.company.com의 A 레코드를 설정하도록합니다.

IP 주소 변경에 대처하는 방법에 대해서는 완벽한 해결책이 없다고 생각합니다. 몇 가지 아이디어는 다음과 같습니다.

  • Use a NAT or IP load balancer and give your customers an IP address belonging to it. If the IP address of the web server needs to change you could make an update on the NAT or load balancer,

  • Offer a DNS hosting service as well and get your customers to host their domain with you so that you'd be in a position to update the A records,

  • Get your customers to set their A record up to one main web server and use a HTTP redirect for each customer's web requests.


Sipwiz is correct the only way to do this properly is the HTTP and DNS hybrid approach. My registrar is a re-seller for Tucows and they offer root domain forwarding as a free value added service.

If your domain is blah.com they will ask you where you would like the domain forwarded to, and you type in www.blah.com. They assign the A record to their apache server and automaticly add blah.com as a DNS vhost. The vhost responds with an HTTP 302 error redirecting them to the proper URL. It's simple to script/setup and can be handled by low end would otherwise be scrapped hardware.

Run the following command for an example: curl -v eclecticengineers.com


You have to put a period at the end of the external domain so it doesn't think you mean customer1.mycompanydomain.com.localdomain;

So just change:

customer1.com IN CNAME customer1.mycompanydomain.com

To

customer1.com IN CNAME customer1.mycompanydomain.com.

I see readytocloud.com is hosted on Apache 2.2.

There is a much simpler and more efficient way to redirect the non-www site to the www site in Apache.

Add the following rewrite rules to the Apache configs (either inside the virtual host or outside. It doesn't matter):

RewriteCond %{HTTP_HOST} ^readytocloud.com [NC]
RewriteRule ^/$ http://www.readytocloud.com/ [R=301,L]

Or, the following rewrite rules if you want a 1-to-1 mapping of URLs from the non-www site to the www site:

RewriteCond %{HTTP_HOST} ^readytocloud.com [NC]
RewriteRule (.*) http://www.readytocloud.com$1 [R=301,L]

Note, the mod_rewrite module needs to be loaded for this to work. Luckily readytocloud.com is runing on a CentOS box, which by default loads mod_rewrite.

We have a client server running Apache 2.2 with just under 3,000 domains and nearly 4,000 redirects, however, the load on the server hover around 0.10 - 0.20.


Thanks to both sipwiz and MrEvil. We developed a PHP script that will parse the URL that the user enters and paste www to the top of it. (e.g. if the customer enters kiragiannis.com, then it will redirect to www.kiragiannis.com). So our customer point their root (e.g. customer1.com to A record where our web redirector is) and then www CNAME to the real A record managed by us.

Below the code in case you are interested for future us.

<?php
$url = strtolower($_SERVER["HTTP_HOST"]);

if(strpos($url, "//") !== false) { // remove http://
  $url = substr($url, strpos($url, "//") + 2);
}

$urlPagePath = "";
if(strpos($url, "/") !== false) { // store post-domain page path to append later
  $urlPagePath = substr($url, strpos($url, "/"));
  $url = substr($url, 0, strpos($url,"/"));
}


$urlLast = substr($url, strrpos($url, "."));
$url = substr($url, 0, strrpos($url, "."));


if(strpos($url, ".") !== false) { // get rid of subdomain(s)
  $url = substr($url, strrpos($url, ".") + 1);
}


$url = "http://www." . $url . $urlLast . $urlPagePath;

header( "Location:{$url}");
?>

참고URL : https://stackoverflow.com/questions/656009/how-to-overcome-root-domain-cname-restrictions

반응형