---
# System prepended metadata

title: CDN
tags: [PROXY, CDN]

---

# CDN

###### tags: `PROXY`,`CDN`


ref: [proxy vs reverse_proxy](https://www.youtube.com/watch?v=ozhe__GdWC8)


### proxy

![](https://i.imgur.com/0Gl3hxe.png)

* anonymity: server doesnt who request
* caching: static artifact(html,js..)
* blocking unwanted site(blacklist)
* geoFencing: political 


### reverse-proxy

![](https://i.imgur.com/qZsk5JD.png)

* load balancing: client doesnt know request to which server, balance load
* caching: caching non-change request
* isolate internal traffic: protect the server from outside open network, increase security
* logging: acknowledge server health
* canary deployment: A canary deployment, or canary release, is a deployment pattern that allows you to roll out new code/features to a subset of users as an initial test.部分測試功能


### CDN: reverse proxy


ref: [CDN](https://www.youtube.com/watch?v=_G08hnoOSZI)
![](https://i.imgur.com/tN530gi.png)

需要DNS給最佳(最近CDN站點)
CDN 反向代理通過緩存來自原始服務器的響應，這些響應正在返回客戶端，從而使這一概念更進一步。因此，CDN 的服務器能夠更快地將資產交付給附近的訪問者。這種方法也是可取的，原因如下：

負載平衡和可擴展性
提高網站安全性

![](https://i.imgur.com/R3oNN7S.png)

1. provider request  DNS best CDN
2. dns return best CDN node address
3. provider provide info to CDN
4. client ask DNS best CDN addr
5. DNS return CDN info to client
6. client ask info to CDN
7. CDN synchronize data(if caching then return directly, or ask server then caching and return these info)
8. CDN return info to client

---

* initial server: 網站數據的主要來源，也是您網站文件的託管位置。例如，如果您使用 DigitalOcean 來託管您網站的文件並選擇了舊金山的數據中心，那麼您的源服務器將位於舊金山。
* edge server:邊緣服務器是用於緩存從源服務器或存儲集群檢索到的內容的 CDN 服務器。另一個經常與邊緣服務器密切相關的術語是存在點presence of point(POP)。POP 是指邊緣服務器所在的物理位置。

:::info
ref: [cdn](https://www.keycdn.com/support/how-does-a-cdn-work)
![](https://i.imgur.com/2CL01Mg.png)
:::

![](https://i.imgur.com/O2qRVf5.png)


### curl check cache

如果您看到 X-Cache 值為 HIT，則表示資產是從 CDN 邊緣服務器的緩存中交付的。否則，如果資產未從緩存中交付，您將看到

X-Cache: MISS表示資產是從您的原始服務器檢索到的。