設定域名的兩三事

上次架站碰上問題後,我開始認真思考要不要有個自己的域名。幾經思考,最後還是決定註冊一個:iigmir.idv.tw。有自己的域名感覺還是比較好,做很多事情會比較容易。

我個人是從匯智資訊註冊域名,因為他們當時有在給 .idv.tw 相當不錯的註冊優惠。五年 1500 就買了。

idv.tw 網域 新註冊/轉入 現正優惠中 現在新註冊或轉入,只要 $300 / 個 / 年起!真香的折扣不買嗎?

真香。

註冊好後我做了點事情玩玩。這裡講下我做的事。

DNS 設定

註冊完網域後,首先最重要的,自然就是 DNS 設定要指向到哪裡去。在你面前會有兩種選擇:一是自管、二是代管。匯智預設是自管,但如果不太懂怎麼接或架 DNS Server 的話,建議讓匯智代管就好。等 DNS 紀錄超過 100 以上時,再考慮搬出去也不遲。

DNS 管理設定。這裡設為 DNS 代管

匯智提供11個類型給我們。這裡會講到 A, AAAA, CNAME 這三種。全部類型可以看英文維基百科。簡單來說:A 對應 IPv4, AAAA 對應 IPv6, CNAME 則對應其他網域。

AWS

AWS 這裡最簡單的服務當然是 Amplify 去弄。不就弄了個 Amplify 實例後去導向域名嗎?有啥難的?

The "tw tld is not supported" message was shown on AWS

Oops... tw tld is not supported!!??

嚇到,難道說 .tw 域名不能用 AWS 嗎?趕緊問 Amazon Q 怎回事:

Hello, I have assign a "example.idv.tw", but the AWS said "tw tld is not supported" -- Doesn that mean, I can never use AWS if my domain ends with ".tw"?

(略) If the TLD you want to use is not supported by Route 53, you may need to consider using a different domain registrar that supports the desired TLD.

What is "different domain registrar" in the article, then? Can I use Amplify without using Route 53?

The key is that you do not need to use Route 53 to register your domain in order to use other AWS services like Amplify. You can use a different registrar and then associate that domain with the AWS services you want to use.

原來是 .tw 域名不能直接用 AWS Route 53 設定域名啊。那就是說要從 different domain registrar ──也就是匯智那邊──設定域名了。

總之 DNS 代管也開了,就用吧。但怎用?

查了下設定說明手冊,其實沒那麼困難。AWS 使用 CNAME 類型,把他給的 CNAME 放到匯智就好了。

……首先,按照說明,如果註冊了 iigmir.idv.tw 的話,假設我還需要個 www.iigmir.idv.tw 的域名、然後 AWS 產生以下紀錄:

Hostname Type Data/URL
_c3e2d7eaf1e656b73f46cd6980fdc0e.iigmir.idv.tw CNAME _cjhwou20vhu2exampleuw20vuyb2ovb9.j9s73ucn9vy.acm-validations.aws
www CNAME d111111abcdef8.cloudfront.net

這個可以去 Action View DNS records 看。但問題是,匯智那邊要怎麼寫呢?針對第一個,那就要把 _c3e2d7eaf1e656b73f46cd6980fdc0e 這玩意貼到匯智的主機名稱、然後對應的 _cjhwou20vhu2exampleuw20vuyb2ovb9.j9s73ucn9vy.acm-validations.aws 貼到設定值。www 也比照辦理:

匯智的主機名稱設定。類型主機名稱填入 _c3e2d7eaf1e656b73f46cd6980fdc0e, 設定值填入 _cjhwou20vhu2exampleuw20vuyb2ovb9.j9s73ucn9vy.acm-validations.aws, TTL選10分鐘

新增成功的話大概是這樣:

匯智的主機名稱顯示。

接著再稍等一會,應該就能上了。而且 Amplify 支援 HTTPS 服務,省去很多時間,實在是太棒了!

我這邊則有個 https://test-aws.iigmir.idv.tw 能看。

Github Pages

完成 Hello World 後就把 Github Pages 的網址 http://iigmir.github.io/blog-v2 改到 http://blog.iigmir.idv.tw 吧。

我原本按照手冊說的,去 Pages 頁面的 Custom domain 設定域名、然後辛苦地把 AAAAA 弄到匯智那邊後,Github Pages 檢查提醒我:

Your site's DNS settings are using a custom subdomain, blog.iigmir.idv.tw, that is set up as an A record. We recommend you change this to a CNAME record pointing to iigmir.github.io. For more information, see documentation (InvalidARecordError).

真親切。
然後我把 AAAAA 全部砍掉後,把 CNAME 加回來,最後 Enforce HTTPS 開啟。完成。

參考資料