cdn工作原理
CDN – you keep seeing the acronym. Maybe in URLs, maybe on landing pages, but it never quite clicked – what are Content Delivery Networks, what do they do exactly?
CDN –您会不断看到缩写词。 也许在URL中,也许在登录页面中,但从未被点击-什么是内容交付网络,它们的作用是什么?
We’ll explain in this overview article, and demonstrate on two popular ones in followup posts.
我们将在这篇概述文章中进行解释,并在后续帖子中演示两个流行的文章。
CDN基础 (CDN Basics)
A CDN is a network of computers that delivers content.
CDN是传递内容的计算机网络。
More specifically, it’s a bunch of servers geographically positioned between the origin server of some web content, and the user requesting it, all with the purpose of delivering the content faster by reducing latency. This is their primary purpose.
更具体地说,它是一堆服务器,地理位置在某些Web内容的原始服务器和用户发出请求的服务器之间,所有这些服务器的目的都是通过减少延迟来更快地交付内容。 这是他们的主要目的 。
These geographically closer servers, also called PoPs or Points of Presence, also cache the cacheable content which removes a lot of the load from the origin server. There are different types of CDNs offering different kinds of services, and they can have differing network topology: scattered CDNs aim to have as many servers scattered around the world as possible. Akamai is one such CDN. Consolidated CDNs have fewer points, but bigger ones built for network performance, throughput, and DDoS resistance.
这些在地理位置上较近的服务器(也称为PoP或存在点)也缓存可缓存的内容,从而减轻了原始服务器的许多负担。 不同类型的CDN提供不同类型的服务,并且它们可以具有不同的网络拓扑 :分散的CDN的目的是在世界范围内尽可能多地分散服务器。 Akamai就是这样的CDN之一。 合并的CDN具有较少的点,但为网络性能,吞吐量和DDoS抵抗而构建的点较大。
CDN的类型 (Types of CDNs)
We said that their primary purpose was to reduce latency and speed up rendering. But in the modern world of 2MB images and 500kb JavaScript libraries that take 3 minutes to boot up on websites, this latency matters little. But there are other purposes to CDNs, too, which evolved over time.
我们说过,它们的主要目的是减少延迟并加快渲染速度。 但是,在2MB图像和500kb JavaScript库的现代世界中,在网站上启动需要3分钟才能启动,这种延迟几乎无关紧要。 但是CDN也有其他目的,随着时间的推移而发展。
面向内容的CDN (Content-oriented CDNs)
Initially, CDNs were just for static content (JS, CSS, HTML). You had to push content to them as you created/uploaded it (they didn’t know they needed to update their cache with your content, not even as someone requested it).
最初,CDN仅用于静态内容(JS,CSS,HTML)。 在创建/上载内容时,您必须将内容推送给他们(他们不知道他们需要使用您的内容来更新其缓存,即使有人请求时也是如此)。
Then, they added origin pulling, making things more automatic – this meant that a user requested the CDN’s URL, and then the CDN requested the origin website’s URL automatically, caching what ever it got back. Additionally, availability became an important factor. Many CDNs now cache a website’s “last alive” state so that if the origin goes down, the CDNed content is still accessible to users, creating the illusion of stability until things return to normal.
然后,他们添加了原始站点拉动 ,使事情变得更加自动化–这意味着用户请求CDN的URL,然后CDN自动请求原始站点的URL,缓存返回的内容。 另外,可用性成为重要的因素。 现在,许多CDN都缓存了网站的“最后生存”状态,因此,如果起源下降了,用户仍然可以访问CDNed内容,从而产生了稳定的幻想,直到一切恢复正常为止。
Additionally, modern CDNs often offer auto-optimization layers which will automagically resize images and save them for future use based on the image size requested. This means what if your site has a 2MB header image and someone requests it on a 300px wide screen, the CDN will make a copy that’s 30kb in size and 300px wide and serve that in the future to all mobile users, automatically making the site faster.
此外,现代CDN经常提供自动优化层,这些层会根据请求的图像大小自动调整图像大小并保存以备将来使用。 这意味着,如果您的网站有2MB的标题图片,并且有人在300px宽的屏幕上请求它,那么CDN会复制一个大小为30kb,宽度为300px的副本,并在将来将其提供给所有移动用户,从而自动使网站速度更快。
面向安全的CDN (Security-oriented CDNs)
The final layer of practicality added to CDNs was DDoS and bot protection. CDNs like Incapsula specialize in this.
CDN中增加的最后一层实用性是DDoS和僵尸程序防护。 像Incapsula这样的CDN专门从事此工作。
As the CDN is the outermost layer of a website’s infrastructure and the first recipient of traffic, it can detect DDoS attacks early and block them with special DDoS protection servers called scrubbers without them ever reaching the origin server and crashing it.
由于CDN是网站基础结构的最外层,并且是流量的第一个接收者,因此CDN可以及早发现DDoS攻击,并使用称为Scrubber的特殊DDoS保护服务器阻止DDoS攻击,而不会到达原始服务器并使之崩溃。
Additionally, by using knowledge crowdsourced from its many clients, a CDN can learn about suspicious IPs, spammers, botters, even types of crawlers and their behavior. For example, a scraper that works on site A will, once identified, stop working on site B as well if that site is protected by the same CDN, because the traffic filter will recognize a pattern it’s seen before.
此外,通过使用从众多客户那里获得的众包知识,CDN可以了解可疑IP,垃圾邮件发送者,破坏者甚至爬虫的类型及其行为。 例如,在站点A上工作的刮板一旦被识别,如果该站点受同一CDN保护,则该站点上的刮板也将停止工作,因为流量过滤器将识别出以前看到的模式。
What’s more, while CDNs do allow their customers to upload custom certificates, they also offer their own. This has two benefits:
而且,尽管CDN确实允许其客户上载自定义证书,但他们也提供自己的证书。 这有两个好处:
- When a big vulnerability in the certificates appears, the CDNs usually quickly respond because they have the most to lose (all their customers). Hence, a fix is usually in place before most people even know about the security hole. 当证书中出现大漏洞时,CDN通常会Swift做出响应,因为它们损失的最多(所有客户)。 因此,通常在大多数人甚至不知道安全漏洞之前就已经有修复程序。
Connections are faster because if many websites use the same CDN, then you’ve already established a valid connection and mutual trust with the CDN via its SSL certificate, and this process does not have to be repeated for every site that uses that CDN’s certificate. This doesn’t impact an individual website as much as it does the entire web.
连接速度更快,因为如果许多网站使用相同的CDN,那么您已经通过其SSL证书与CDN建立了有效的连接并相互信任,并且不必为使用该CDN证书的每个站点重复此过程。 这对单个网站的影响不如对整个网站的影响大 。
最大的玩家 (Biggest Players)
Some of the biggest players in the CDN space are companies like Akamai, AWS Cloudfront, Cloudinary, Incapsula, MaxCDN, Fastly, and others.
CDN领域中一些最大的参与者是Akamai,AWS Cloudfront,Cloudinary,Incapsula,MaxCDN,Fastly等公司。
Rather than compare them in full, we’ll list the categories in which each can be a champion:
与其完整地比较它们,不如列出它们可以成为冠军的类别:
爬网和DDoS保护 (Scraping and DDoS Protection)
While fine in every other way too, Incapsula is unbeatable in scraping and DDoS protection. With an extensive database of not only offending proxy IP addresses but also mouse and browsing patterns of bots and scrapers, Incapsula stops most automated attacks dead in their tracks.
尽管在其他方面也不错,但Incapsula在抓取和DDoS保护方面无与伦比。 凭借庞大的数据库,该数据库不仅包含有问题的代理IP地址,而且还包含机器人和爬虫的鼠标以及浏览模式,可以阻止大多数自动攻击消失在他们的轨道上。
Choose if: you’re a web shop and don’t want your competitors to scrap your catalog
选择是否:您是网上商店,不想让竞争对手放弃您的目录
速度与全球影响力 (Speed and Global Reach)
Akamai, the CDN that even Facebook uses, has a proven track record of global availability. Their scattered model of network topology and availability in even the poorer parts of the world (something other CDNs lack) make content served with Akamai smooth to load even in low-connectivity areas. A close second is AWS Cloudfront from Amazon.
Akamai,甚至Facebook都使用的CDN,在全球可用性方面拥有良好的记录。 他们分散的网络拓扑模型以及在世界上最贫困地区(其他CDN缺乏的可用性)的可用性,使得即使在低连通性区域中,也可以使用Akamai平滑地加载内容。 紧随其后的是来自亚马逊的AWS Cloudfront。
Choose if: you’re aiming for global reach, from China to US, from Finland to Antarctica.
选择是否:您的目标是从中国到美国,从芬兰到南极洲的全球业务。
负担能力 (Affordability)
Amazon Cloudfront is the cheapest of the paid plans (we don’t count free plans as those often lack important features) and has the arguably largest reach after Akamai, which isn’t exactly cheap (a scattered topology is expensive to maintain).
Amazon Cloudfront是付费计划中最便宜的(我们不算免费计划,因为这些计划通常缺少重要的功能),并且可以说是仅次于Akamai的最大覆盖范围,而且价格也不是那么便宜(分散的拓扑维护起来很昂贵)。
Choose if: price is an issue.
选择是否:价格是一个问题。
热连结 (Hotlinking)
Hotlinking is when someone selects “Copy image address” on an image hosted on your website, and includes it in their own directly, with the original URL intact. This is usually sloppy and lazy work on the side of content thieves, but can lead to big expenses if the copycat succeeds in sharing their site on large-impact social media website like Facebook or Reddit, and your server suffers for it. MaxCDN and KeyCDN both offer very good hotlinking protection.
热链接是指当有人在您网站上托管的图像上选择“复制图像地址”,并直接将其直接包含在原始URL中的情况下。 这通常是内容盗窃者的草率和懒惰工作,但是如果模仿者成功地在影响力较大的社交媒体网站(如Facebook或Reddit)上共享其网站,并且您的服务器因此遭受苦难,则可能会导致巨额费用。 MaxCDN和KeyCDN都提供了很好的热链接保护。
Choose if: you’ve got a gallery, travel blog, or any other image-rich site which is at risk of hotlinking.
选择是否:您有一个画廊,旅游博客或任何其他具有大量图像的网站,这些网站可能会发生热链接。
其他 (Other)
We encourage you to go out and investigate on your own. There are countless posts comparing the CDNs one to the other, and each plan of each CDN differs in offered options to the next one. It’s extremely difficult to cover them all, and the landscape constantly changes.
我们鼓励您自己出去调查。 有不计其数的职位将CDN相互比较,每个CDN的每个计划在提供的选项上都与下一个有所不同。 覆盖所有这些极其困难,并且景观不断变化。
实施过程 (Implementation Process)
Implementing a CDN typically entails changing some DNS records in the control panel of the registrar (the company renting you your domain name). This results in all traffic hitting the CDN first, which in turn hits your website. Since it all happens behind the scenes (through IPs), the process is transparent to the user.
实施CDN通常需要在注册商(您租用您的域名的公司)的控制面板中更改一些DNS记录。 这导致所有流量首先到达CDN,进而又到达您的网站。 由于这一切都是在后台进行(通过IP),因此该过程对用户是透明的。
Sometimes, sites will add a special subdomain to their main domain on which to host images, JavaScript, CSS, and other static content. If you open the Network tab of a browser’s dev console or just pay attention to the status bar of your browser while a site like Facebook is loading, you’ll notice a lot of URLs with cdn
in them – that’s the site in question requesting only some of its content from CDNs.
有时,网站会在其主域中添加一个特殊的子域,以在其上托管图像,JavaScript,CSS和其他静态内容。 如果您在打开诸如Facebook之类的网站时打开浏览器的开发控制台的“网络”标签,或者只是在浏览器的状态栏上关注,您会注意到其中包含cdn
的很多URL –这就是该站点仅在请求它的某些内容来自CDN。
Why not request all content through CDNs? Because static content is usually big – 2MB images, 500kb of JS, etc. This is worth serving quickly, because a) it doesn’t change often and can be cached for a long time and b) removes a big, big load from the main server of the app, which can be dynamic.
为什么不通过CDN请求所有内容? 因为静态内容通常很大-2MB图像,500kb JS等,所以值得快速提供,因为a)它不会经常更改并且可以长时间缓存,并且b)消除了静态内容的巨大负担。应用程序的主服务器,可以是动态的。
结论 (Conclusion)
In this article, you learned what a CDN was and how it works. You found out about the different types of CDNs and their potential scope of work, as well as the biggest players in the field.
在本文中,您了解了什么是CDN及其工作方式。 您了解了CDN的不同类型及其潜在的工作范围,以及该领域的最大参与者。
In two followup articles we’ll introduce Cloudinary and Cloudflare, and in our major Performance-Month-Project we’ll actually implement one of them into our real world app so you can see it in action on a live example. Stay tuned!
在两篇后续文章中,我们将介绍Cloudinary和Cloudflare,在我们的主要Performance-Month-Project中,我们实际上将其中之一实现到我们的真实应用程序中,以便您可以在实际示例中看到它们。 敬请关注!
翻译自: https://www.sitepoint.com/what-is-a-cdn-and-how-does-it-work/
cdn工作原理