目录
前言
云服务器用起来感觉最难受的就是带宽了,国内的云服务器普遍带宽都很小,但买国外或者香港的话延迟大还容易被封IP。一般网站/app最占带宽的是图片和音视频等文件的上传下载,下面我们要聊的cos和cdn就是解决这个问题来的。
简介
对象存储COS
- 对象存储不同于我们平时操作系统里的文件存储,它就像一个map,存储的所有文件都有一个唯一的名称作为key,文件内容作为value。而没有目录的概念。
- 这样做的意义在于,当文件很多,目录结构深时,文件存储需要根据那颗目录树一步一步找到文件,显然是比对象存储直接按文件名一步到位得到要来得慢。
- 但目前很多云服务厂商都有在对象存储上提供目录功能,这大多是模拟出来的。比如腾讯云是将文件名中的 / 识别为目录模拟得到的。
- 比如:放进两个文件:
- aaa.txt
- wow/abc.cpp
- 由于 "wow/abc.cpp" 的文件名带有 / ,则可以模拟解析为是放在wow目录下,存在一个文件叫abc.cpp。
- 我们使用云服务提供的COS来替换我们的服务器实现文件的上传和下载。一般云服务COS不限制下载速度,且用户上传也免费。但用户的下载流量、存储空间占用、请求次数是要收钱的。
- 注意这不是三选一的问题,是三个方面都要收钱的!
- 比如:在一个月的时间里,我们向COS上传了 100 MB 文件,发送过 1 w 次读写请求,且用户外网下载文件使用过 10G 的流量。
- 那么结算时,需要支付:A + B + C
- A:100M/1个月 的存储空间占用费用
- B:1w次读取请求费用
- C:外网下载 10 G 流量费用
- 显然,外网下载流量很容易被人攻击,盗刷流量,然后疯狂扣流量包扣费,容易出现一觉醒来,没了一套海景房的刺激。后面我们用CDN来防止一部分攻击,因为COS的流量费比CDN贵非常多,而且CDN能设置更多的访问限制,降低被攻击的损失,所以可以用CDN抗在前面。
CDN
- cdn的用途很广泛,由于用户在地域上分布全国甚至全球各地,而我们的服务器一般是只在一个或几个地方而已,cdn在地域上可以分散多个节点,作为一个中间人,缓存用户访问服务器上的文件,并在用户下一次请求这个文件时,cdn就可以直接提供给用户,而不需要大老远来请求服务器,提高用户的访问速度。
- 这里我们可以利用这个特性,且其价格低,来帮助COS降低被攻击的损失。
使用问题
盗刷COS流量
- 前面我们已经提到,COS的外网下载流量是比较贵的,而且速度快,容易被攻击刷流量。
- 解决办法:
- 把COS访问权限设置为 私有读私有写
- 当用户需要上传文件时,使用云厂商提供的SDK,服务端预签名上传文件的URL,并将签名后的链接发送给用户,客户端只能按照签名链接指定参数、请求头、请求类型的上传文件到COS,上传不需要使用CDN。
- 当用户需要下载时,使用SDK获取COS上对应文件名的文件链接,并将链接的域名替换为CDN的域名,然后返回替换后的链接给用户下载文件,并在CDN设置限制IP访问速度、下载速度等限制即可。
防盗链/限速
- 由于浏览器不允许伪造请求头中的Referer、Host、Origin,因此可以在CDN/COS都配置防盗链,限制请求的Referer。这个可以阻止别人的网站直接把你的资源链接放到他的网站使用的情况,减少一些被偷资源流量的问题,但他直接下载你的资源然后上传到他的服务器还是可以的。
- 注意网页是可以指定浏览器不携带Referer的,即请求是空Referer。而在浏览器直接敲网址进入网页时的请求也是空Referer,你需要考虑是否需要允许空Referer的请求。防盗链挡不住客户端请求,因为客户端是可以随意伪造请求中的任意值的。如APP、nodejs、命令行、服务端程序等,只要是非标准浏览器环境就可以随意伪造。
- 在CDN中,可以限制下载速度、IP访问速度等。
https网站中使用http资源
- 由于CDN的Https目前很多云厂商是收费的,虽然不贵,但也是钱。
- 如果你CDN访问使用了http,但网站是https协议时,直接在https网站里获取http资源(图片、音视频等)会被浏览器认为是不安全的,并在浏览器的开发者工具中打印警告,但也是能用的。但默认不会带上Referer,因此如果你设置了防盗链不允许空Referer的话,就有问题了,这个时候可以在网页的<head></head>中添加配置:<meta content="always" name="referrer" >,这样浏览器在获取Http资源时也会带上Referer了
- https网站中发起http请求是不允许的!
上传文件大小/数量限制
- 用户向我们的服务端申请用于上传文件的预签名URL时,需要携带参数:文件大小、文件MD5,然后我们可以指定该链接发送时必须携带:
- Content-Length=500
- x-cos-meta-md5: {文件md5值}
- 由此就可以防止用户拿到预签名URL后,上传了其他文件的问题
- 文件大小限制,就是在我们服务端给预签名URL时进行检查。
- 文件数量限制,可以将用户、IP获取上传链接时写入数据库记录,根据这个记录来设计用户上传文件的数量和总大小等。
腾讯云COS的SDK/c++
- 整了老半天,终于写好了cmakelist能编译运行release,但debug版一直找不到链接符号。
- 看了大概是因为他是SDK源码里有一个文件夹three-party存放了已经编译好的第三方依赖库,但这些库是release的,因此需要我们编译debug的依赖库。但我的项目里也依赖openssl,改来改去才能release,最终debug版放弃了。
- 后来开始用上go了,学1天然后上手引入他的sdk和框架开发完cos相关的接口。有c基础还是很快上手的。
Thank you great posting about essential oil. Hello Administ . 国产线播放免费人成视频播放
I highly advise to avoid this site. The experience I had with it has been only frustration and concerns regarding deceptive behavior. Be extremely cautious, or even better, seek out an honest service to meet your needs.
Great post thank you. Hello Administ . Seo Hizmeti Skype : live:by_umut
After all, what a great site and informative posts, I will upload inbound link – bookmark this web site? Regards, Reader.儿童色情片
I urge you to avoid this platform. My personal experience with it was purely disappointment as well as suspicion of scamming practices. Proceed with extreme caution, or alternatively, seek out a trustworthy service for your needs.
Hi, every time i used to check webpage posts here in the early hours in the dawn,
because i love to learn more and more.
1. Как установить кондиционер в доме
продажа кондиционеров https://prodazha-kondcionerov.ru/ .
Как установить оконный кондиционер: инструкция для начинающих
стоимость установки кондиционера https://ustanovka-kondicionera-cena.ru/ .
I highly advise to avoid this site. My own encounter with it was purely disappointment as well as suspicion of scamming practices. Be extremely cautious, or even better, look for a trustworthy site for your needs.
Установка кондиционера: как не нарваться на ошибки
мастер кондиционер https://ustanovka-kondicionera-cena.ru/ .
I urge you steer clear of this platform. My personal experience with it has been only disappointment and suspicion of deceptive behavior. Be extremely cautious, or alternatively, seek out an honest service to fulfill your requirements.
I strongly recommend stay away from this platform. My personal experience with it has been purely frustration as well as doubts about fraudulent activities. Proceed with extreme caution, or better yet, seek out an honest platform for your needs.
Great post thank you. Hello Administ . 国产线播放免费人成视频播放
ABANT-YEDİGÖLLER- AĞVA –ŞİLE –POLENEZKÖY-HOBBIT EVLERİ 2GÜN-1GECE
I urge you steer clear of this platform. The experience I had with it was purely disappointment along with concerns regarding scamming practices. Be extremely cautious, or alternatively, seek out a trustworthy service to fulfill your requirements.
Руководство по установке кондиционера: детальные шаги и советы для успеха
монтаж кондиционера цена https://ustanovka-kondicionera-cena.ru/ .
Hi! This post could not be written any better!
Reading this post reminds me of my good old room mate! He always kept
talking about this. I will forward this post to him.
Pretty sure he will have a good read. Thank you for sharing!
sandyterrace.com
함대의 파괴는 주요 사건이며 수백 명의 사상자가 주요 사건 인 것 같습니다.
1. Как установить кондиционер в доме
оборудование для кондиционирования оборудование для кондиционирования .
Hi colleagues, good paragraph and pleasant urging commented at
this place, I am really enjoying by these.
Установка кондиционера в квартире: что нужно знать
ремонт кондиционера https://ustanovka-kondicionera-cena.ru/ .
Thank you for great article. Hello Administ .国产线播放免费人成视频播放
Добрый день всем!
Поможем выбрать, оформить заказ и купить диплом любого института в любом городе по самым низким ценам
http://saksx-attestats.ru/
Приобретите диплом колледжа недорого с доставкой по РФ и гарантией качества без предварительной оплаты – просто и надежно!
Компания предлагает купить диплом Вуза России недорого, без предоплаты и с гарантией возврата средств.
Hi there, I log on to your blog daily. Your writing style is awesome,
keep it up!
Greate post. Keep posting such kind of info on your site.
Im really impressed by your site.
Hey there, You have done a fantastic job. I will definitely digg it and
individually recommend to my friends. I am confident they’ll be benefited from this website.
Hello there I am so glad I found your web site, I really found you by
error, while I was searching on Google for something else, Anyhow I am here now and would just like to say cheers for a tremendous post and a all round interesting blog (I also love the theme/design), I don’t have time to read
it all at the minute but I have book-marked it and also included your RSS feeds, so when I have time I will be back to read much more, Please do keep up the fantastic
work.
Thank you for great information. Hello Administ . 国产线播放免费人成视频播放
Привет, дорогой читатель!
Приобретите документ об образовании по выгодной цене с доставкой по РФ и оплатой после получения ваших руками!
купить аттестат цена
Приобретите диплом института или колледжа с гарантией качества и доставкой по России без предоплаты.
Приобретите диплом института или колледжа недорого с доставкой по РФ и гарантией качества без предварительной оплаты!
Привет всем!
Закажите диплом ВУЗа с доставкой по России без предоплаты и с гарантией подлинности – удобно и безопасно!
купить аттестат за 11
Купите диплом института или колледжа с гарантированной подлинностью и доставкой по России без предоплаты – удобно, безопасно, выгодно!
Приобретите документы об образовании всех ВУЗов России по выгодным ценам с постоплатой и помощью 24/7!
E-learning is definitely transforming the the perspective we have on conventional education. In Alabama, we have many superb online schools providing a uninterrupted learning experience to students. Everyone have the possibility to organize their schedules as they engage in superior, flexible educational programs. Such platforms not just service diverse academic needs, but they also encourage students to study at their own speed, boosting comprehension and retention along the way.
Several of these online schools in Alabama provide a comprehensive curriculum covering both core subjects and electives. Students can pursue their interests while keeping a focus on mandatory courses. Moreover, for students who excel in an individual learning environment, the online option can be particularly beneficial.
Additionally, it's notable that these online schools are not just about virtual lectures and assignments. Several schools offer interactive sessions, multimedia shows, and even practical experiments virtually – broadening horizons in an optimum learning environment.
As we wade through this emerging educational landscape, it's crucial to stay informed on the available options. I strongly recommend looking into your online schooling options in Alabama to ensure a suitable fit for your individual situation, learning preferences, and professional goals. Get more information about more about online schools in Alabama – the new phase of education is here and now! https://www.onlineschoolAL5.com
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across. Seo Hizmeti Skype : live:by_umut
very good jon mate. very useful to me tahnxss Free Twitter Followers => https://bit.ly/postegro-nunu
Hello there! This post could not be written any better!
Looking through this article reminds me of my
previous roommate! He constantly kept preaching about this.
I will forward this post to him. Fairly certain he will have a great
read. Thank you for sharing!
Привет всем!
Рады предложить Большой выбор документов об образовании всех Вузов России, недорого, с постоплатой, помошь 24/7
http://saksx-attestats.ru/
Закажите диплом ВУЗа с гарантированной подлинностью и доставкой по России без предварительной оплаты – просто, надежно, выгодно!
Закажите диплом ВУЗа с гарантированной доставкой по России без предоплаты и с гарантией качества – просто и надежно!
I highly advise stay away from this site. My own encounter with it has been purely dismay along with concerns regarding scamming practices. Exercise extreme caution, or even better, find an honest platform to meet your needs.
I strongly recommend stay away from this platform. My own encounter with it was only dismay as well as doubts about deceptive behavior. Proceed with extreme caution, or better yet, seek out an honest site for your needs.
I highly advise stay away from this platform. My own encounter with it was nothing but dismay as well as concerns regarding deceptive behavior. Exercise extreme caution, or better yet, seek out an honest site to fulfill your requirements.
I urge you stay away from this platform. My personal experience with it has been nothing but frustration as well as suspicion of deceptive behavior. Be extremely cautious, or even better, look for an honest service to meet your needs.
Very well presented.very quote was awesome and thanks for sharing the content.
I strongly recommend stay away from this site. The experience I had with it was purely disappointment along with suspicion of scamming practices. Be extremely cautious, or alternatively, look for a more reputable site for your needs.
It’s very effortless to find out any topic on net as compared
to textbooks, as I found this post at this website.
Here is my website – 카지노사이트
фильм
I strongly recommend stay away from this platform. The experience I had with it was only dismay as well as doubts about deceptive behavior. Exercise extreme caution, or alternatively, find a trustworthy service for your needs.
https://jeneri.ru/beg-i-potenciya.html
Awesome post.
Thank you a lot for sharing this with all folks you really recognize what
you’re speaking approximately! Bookmarked. Kindly also talk over with
my web site =). We could have a hyperlink change agreement
between us
very good jon admin. very useful thx Free Twitter Followers => https://bit.ly/Get-Free-Twitter-Followers
сериал онлайн
кондиционеры для дома https://split-sistema-kupit.ru/ .
split система https://split-sistema-kupit.ru/ .