Azure – Front Door (AFD)

前言

会研究到 Azure Front Door (AFD) 是因为想安装 WAF. 结果研究了一圈, 发现 AFD 好弱啊. 

有许多功能都有 limitation. 

Limitation & 不够好的地方

1. Not support web socket

参考: feedback.azure.com

另外 CDN 也是不支持 web socket.

Application Gateway 就支持. Cloudflare 也支持. 所以 AFD, ACDN 都很差..

 2000 votes 排名第 3,

2. Root domain setup 很麻烦

参考: Onboard a root or apex domain on your Front Door

AFD 的 setup 方式是在 DNS point to AFD, 用的是 CNAME. 而 root domain 是 @ 无法配上 CNAME

只可以用 A point IP. 所以需要额外搞 ALIAS record, 我不清楚是不是只有 Azure DNS 才可以搞这些啦.

2.1 Root domain 要自己搞 certifiate 

目前 managed certificate 不支持 , 需要自己弄 certificate 然后通过 Key Vault 链接到 AFD.

3. AFD Standard/Premium 还在 preview 中

参考: What is Azure Front Door Standard/Premium (Preview)?

虽然有 50% discount 但 not recommended for production, 谁还敢用丫.

4. Wildcard domains setup 很麻烦

参考: Wildcard domains

只能用 CLI 不能用 portal setup

只能自己做 certificate

基本架构概念

Front Door "前门", 顾名思义就是请求到达服务器之前的门口. 

普通架构里, DNS 直接 point 去 VM. 这样的方式不安全. IP 直接公开, 而且只能对一台服务器. 

DNS > AFD > VMs pool 这样的架构就好多了, 可以做很多事情, 缓存啦, WAF 啦, load balance 啦. 而且对外也隐藏了服务器的 IP.

Azure 有很多种类似的服务. 每个都针对不太一样的场景, 但又非常类似. 

Application Gateway focus load balance

CDN focus static files

AFD focus Web, API, Compute

所以最终 AFD 推出了 Standard/Premium 版本, 综合了大家的服务. (但目前任在 preview 当中... 又 preview ?!)

AFD Classic Step by Step

由于 Standard/Premium 还在 preview 而且也贵, 先介绍原始版本吧. 

Setup VM DNS Name

CDN > AFD > VM,

首先 AFD > VM 最好不要直接使用 IP, 因为用 IP 就做不了 TLS (SSL). 

所以先让 VM 有一个 domain name (用 Azure 的就可以了)

参考: Create a fully qualified domain name for a VM in the Azure portal

进入 VM > Properties > DNS name label

我这张图是已经做好的, 本来应该是 none, 点击进入然后取一个名字

这样就可以了.

Create AFD

搜索 front door service

点击创建, (它属于 Load balancing 的一种)

选好 Resource Group

进入关键的地方了

Frontends/domains 是从 DNS point 进来的入口.

Session Affinity 是指是否让用户固定用一个 VM, 如果我们的服务是无状态的那么就可以不开, 但如果是有需要维护 session 之类的, 那么最好是让用户固定使用一台 VM.

WAF 可以之后才加进去.

Backend pools 是我们的 VMs

可以放多个 VMs, 它会挑选比较不忙的去 serve request.

点击 Add a backend

选择 custom host, 然后把我们上一个环节做的 VM DNS name 放进去. 这里需要注意一点.

一般上一个 VM 只服务一个 Web App. 所以端口用 80, 443 就可以了. 但是如果我们的 VM 是 serve multiple web apps 的话.

那么这里就需要分不同的端口了. 

IIS 的 setup, 当 AFD > VM 的时候就是这样访问的

注: 81, 444 需要去 Azure portal 添加 Inbound port rules, 也需要在 VM 里面开启 firewall advanced 添加 inbound port 哦

其余的默认就可以了

Routing ruls 是它们 2 个之间的 mapping

取个名字, 上半部分是选 frontends/domains

下半部分是选 backend pool

第一轮的 setup frontend 是 azure 的 sub domain 比如: test-front-door.azurefd.net

需要在添加多一个 frontend for custom domain

这时会看到多了一个 Custom host name 和 TLS

把 Frontend host name copy 去 DNS Custom domain 的 CNAME (上面有说了 root domain 的话需要更麻烦的 setup, 这里说的都是 sub domain)

然后开启 TLS. Azure 会自动去申请 certificate (sub domain only). 这个过程可能需要 20 分钟

然后在重复 setup backend 和 route 就可以了.

最后大概长这样

About TLS

End-to-end TLS with Azure Front Door

最好是全程使用 TLS.

CDN > AFD 使用 Azure managed certificate

AFD > VM, 需要 VM 申请 VM DNS Name (azure 的 sub domain, e.g. test-front-door-vm.southeastasia.cloudapp.azure.com) 的 certificate, 通常是用 Let's Encrypt.

重点 highlight

如果熟悉它的原理, setup 并不算难, 我自己卡很久都是因为基础不太好. 

这里总结一下.

在 DNS 做一个 custom sub domain 通过 CNAME point to AFD frontend (test-front-door.azurefd.net)

这样用户访问就会进入到 AFD 了.

下一步是 front door 去 VM. 这里可以用 VM 的 IP, 但是这样就没有 TLS, 所以最好用 VM 的 DNS name (test-front-door-vm.southeastasia.cloudapp.azure.com) 

配上不同 port 就可以实现 VM multiple web app. (记得要 set Azure portal 和 VM firewall 的 inbounce rule)

最后是 mapping, 这个没有什么特别要注意的. 

总结

感觉它还有很多不方便的地方,学习资源也不多. 不推荐使用. 我只是把目前做到的研究记入一下而已.

可以考虑 Cloudflare 作为替代.

原文地址:https://www.cnblogs.com/keatkeat/p/15809172.html