目录
前言
云服务器用起来感觉最难受的就是带宽了,国内的云服务器普遍带宽都很小,但买国外或者香港的话延迟大还容易被封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基础还是很快上手的。
aramalarım sonunda buraya geldim ve kesinlikle işime yarayan bir makale oldu. teşekkür ederim
With havin so much written content do you ever run into any issues
of plagorism or copyright violation? My site has a lot of exclusive content I’ve either authored myself or
outsourced but it appears a lot of it is popping it up all over the
web without my authorization. Do you know any techniques to help stop content from being
stolen? I’d certainly appreciate it.
Hocam Ellerinize Saglık Güzel Makale Olmuş Detaylı
I highly advise stay away from this platform. My personal experience with it has been nothing but dismay and doubts about fraudulent activities. Exercise extreme caution, or alternatively, look for a more reputable platform to meet your needs.
I highly advise to avoid this site. My personal experience with it has been only dismay and suspicion of scamming practices. Exercise extreme caution, or even better, look for an honest platform to fulfill your requirements.
I every time emailed this website post page to all my contacts, because if like to read it afterward my links will too.
aydın çıkışlı turlar
Interacting via comment forms is an eloquent expression of contemporary business interaction, merging the finest of discretion and tech. This method offers companies a unswerving line to their consumers, permitting them to grasp the subtleties of user interaction, garner helpful feedback, and, above all, demonstrate that they are continually hearing. Instead sifting through the jammed terrain of emails and marketing messages, feedback forms offer a clutter-free space, paving the path for true dialogue and further involved conversations.
Furthermore, communicating to response forms is a proof to a business’s dedication to incessant enhancement. Rather of working in a vacuum, businesses get an invaluable perspective into their clients’ minds, opening up opportunities for growth, enhancement, and creating tighter ties. As customer needs evolve, this reciprocal interaction channel confirms that businesses remain not merely relevant but intimately tied to their market’s ever-changing likes and fears. In the vast scheme of things, it’s not merely about collecting feedback; it’s about nurturing trust and cementing bonds that stand the test of time.
Telegram: @xrumers
https://XRumer.art
Skype: XRumer.pro
мульти сплит система кондиционер https://multisplit-sistemy-kondicionirovaniya.ru/ .
сплит кондиционер сплит кондиционер .
I strongly recommend to avoid this site. My personal experience with it has been only disappointment as well as suspicion of scamming practices. Exercise extreme caution, or even better, seek out a trustworthy platform to meet your needs.
I highly advise stay away from this site. My own encounter with it was purely dismay as well as doubts about deceptive behavior. Be extremely cautious, or better yet, find an honest site for your needs.
I strongly recommend steer clear of this site. The experience I had with it was nothing but frustration and suspicion of deceptive behavior. Proceed with extreme caution, or alternatively, look for a more reputable site for your needs.
Inside the constantly changing arena of SEO, tools and tactics that can effectively increase a website’s digital presence are in persistent demand. Enter XRumer, a modern software built to power up link-building efforts. With the aid of the ability to post on message boards, weblogs, guestbooks, and various platforms by default, XRumer transforms the way digital marketers handle off-page SEO. This powerful tool circumvents usual online obstacles like CAPTCHAs, making sure an uninterrupted and efficient backlink production method. A skillfully executed XRumer SEO run can considerably increase a site’s search engine rankings, driving organic traffic and improving online appearance.
Yet, while the capability of XRumer is indisputable, its use necessitates a strategic and wise strategy. Like all SEO tools, the consequences are just as good as the strategy after them. Too much reliance or misuse could lead to undesired results, like punishments from search engines for unnatural link building. Consequently, when commencing on an XRumer SEO run, it’s vital to emphasize excellence over number, aiming at pertinent and high-authority sites that align with the brand’s values. In the hands of a talented SEO specialist, XRumer turns into a formidable asset, connecting the divide between a brand and its internet potential.
Telgrm: @exrumer
https://XRumer.cc/
Skype: XRumer.pro
aydın çıkışlı turlar
I strongly recommend stay away from this site. My personal experience with it has been nothing but dismay as well as concerns regarding fraudulent activities. Be extremely cautious, or even better, look for a trustworthy platform to meet your needs.
Excellent post. I was checking constantly this blog and I am inspired!
Very helpful info particularly the closing phase 🙂 I deal with such information a lot.
I was seeking this particular information for a very lengthy time.
Thank you and good luck.
I really like reading through a post that can make men and women think. Also, thank you for allowing me to comment!
Great beat ! I would like to apprentice whilst you amend your website, how can i subscribe for a blog site?
The account aided me a appropriate deal. I had been tiny bit familiar
of this your broadcast offered shiny transparent concept
кондиционеры сплит системы https://multisplit-sistemy-kondicionirovaniya.ru/ .
Your blog has helped me become a more positive and mindful person I am grateful for the transformative effect your words have had on me
I might like this blog, my brother said, and he was entirely right. Seeing this post made my day. You are not aware of the amount of time I invested in finding this information.
Love this appreciation for great content
bu konuda bu kadar net bilgiler internette malesef yok bu yüzden çok iyi ve başarılı olmuş teşekkürler.
Your positivity and enthusiasm are contagious Reading your blog has become a part of my daily routine and I always leave feeling better than when I arrived
This blog post is packed with great content!
системы кондиционирования https://multisplit-sistemy-kondicionirovaniya.ru/ .
ısı yalıtımı
I really love to read such an excellent article. Helpful article. Hello Administ . Seo Hizmeti Skype : live:by_umut
Your writing style is so relatable and authentic It’s a breath of fresh air in a world filled with superficiality and pretense
Доброго всем дня!
Наша компания предлагает конфиденциально выбрать и заказать диплом любого Вуза России
http://saksx-attestats.ru/
Закажите диплом ВУЗа с доставкой по России без предоплаты и с гарантией подлинности – удобно и безопасно!
Закажите диплом ВУЗа по выгодной цене с доставкой в любой город России без предоплаты – это надежно и выгодно!
Полезные советы
2. Шаг за шагом: установка кондиционера своими руками
3. Важные моменты при установке кондиционера в квартире
4. Специалисты или самостоятельная установка кондиционера?
5. 10 шагов к идеальной установке кондиционера
6. Подробная инструкция по установке кондиционера на балконе
7. Лучшие методы крепления кондиционера на стену
8. Как выбрать место для установки кондиционера в комнате
9. Секреты успешной установки кондиционера в частном доме
10. Рассказываем, как правильно установить сплит-систему
11. Необходимые инструменты для установки кондиционера
12. Какие документы нужны для оформления установки кондиционера?
13. Топ-5 ошибок при самостоятельной установке кондиционера
14. Установка кондиционера на потолке: особенности и нюансы
15. Когда лучше всего устанавливать кондиционер в доме?
16. Почему стоит доверить установку кондиционера профессионалам
17. Как подготовиться к установке кондиционера в жаркий сезон
18. Стоит ли экономить на установке кондиционера?
19. Подбор оптимальной мощности кондиционера перед установкой
20. Какие бывают типы кондиционеров: сравнение перед установкой
кондиционер обслуживание кондиционер обслуживание .
Здравствуйте!
Приобретите диплом института или колледжа недорого с доставкой по РФ и гарантией качества без предварительной оплаты!
http://saksx-attestats.ru/
Закажите диплом ВУЗа с гарантированной подлинностью и доставкой по России без предварительной оплаты – просто, надежно, выгодно!
Приобретите диплом Вуза с доставкой по России без предоплаты и полной уверенностью в его подлинности.
animehangover.com
“이 주식 왜이래, 이상한 거 없어?”
Полезные советы
2. Шаг за шагом: установка кондиционера своими руками
3. Важные моменты при установке кондиционера в квартире
4. Специалисты или самостоятельная установка кондиционера?
5. 10 шагов к идеальной установке кондиционера
6. Подробная инструкция по установке кондиционера на балконе
7. Лучшие методы крепления кондиционера на стену
8. Как выбрать место для установки кондиционера в комнате
9. Секреты успешной установки кондиционера в частном доме
10. Рассказываем, как правильно установить сплит-систему
11. Необходимые инструменты для установки кондиционера
12. Какие документы нужны для оформления установки кондиционера?
13. Топ-5 ошибок при самостоятельной установке кондиционера
14. Установка кондиционера на потолке: особенности и нюансы
15. Когда лучше всего устанавливать кондиционер в доме?
16. Почему стоит доверить установку кондиционера профессионалам
17. Как подготовиться к установке кондиционера в жаркий сезон
18. Стоит ли экономить на установке кондиционера?
19. Подбор оптимальной мощности кондиционера перед установкой
20. Какие бывают типы кондиционеров: сравнение перед установкой
вентиляции и кондиционирования https://prodazha-kondcionerov.ru/ .
Exploring the intricacies of digital schools located in Alaska can certainly be difficult, mainly if you're unfamiliar to the concept. I, too, confronted these issues but realized that these digital platforms deliver a high-quality, complete educational venture that competes with usual brick-and-mortar schools.
Originating from the rugged landscapes of Juneau to the active ambiance of Anchorage, Alaska's online schools serve numerous learning opportunities that are adjustable and suitable. The snow-filled winters not anymore obstruct an individual's ability to obtain schooling. Up-to-date technology has made it possible to follow knowledge from the comfort and comfort of your own home.
Adaptability is a remarkable benefit. You can modify your schedules according to your duties, which happens to be specifically advantageous for working individuals or those with family obligations. Additionally, the courses provided are varied, inclusive of a wide range of subjects. Including introductory basics to higher specialties, there are something interesting for everyone.
Alaska's online schools present well-qualified teachers, active learning techniques, and assisting peer networks, making for a deep gratifying educational journey. If you've been contemplating enrolling, I urge you to take that leap and discover Alaska's innovative online education. Discover more about this groundbreaking strategy to wisdom and just how it can potentially revamp your education and career trajectory. https://www.onlineschoolAK10.com/
YOKIDOLLは、高品質を提供する最高のオンラインストアです。これからすべての性的欲求を満足させ、新しいラブドール販売で最新の人気を手頃な価格で当社のウェブサイトをご覧ください。
su yalıtımı
Wow, wonderful weblog layout! How long have you ever been running a blog for?
you make blogging glance easy. The total glance of your site is wonderful, let alone the content!
I urge you steer clear of this site. The experience I had with it has been purely frustration as well as suspicion of fraudulent activities. Proceed with extreme caution, or alternatively, find a trustworthy service to fulfill your requirements.
Thanks for sharing yourr thoughts on cdn. Regards
Also visit my homepage … 카지노사이트
Добрый день всем!
Наш интернет-магазин предлагает купить российский диплом по выгодной цене, с гарантией прохождения всех проверок
сколько купить аттестат
Купите диплом Гознака с гарантированной подлинностью и доставкой по всей России без предоплаты – просто и безопасно!
Закажите диплом Вуза с гарантией качества и доставкой по всей России без предоплаты.
I highly advise stay away from this platform. My personal experience with it has been purely disappointment along with doubts about fraudulent activities. Proceed with extreme caution, or even better, look for an honest site for your needs.
I highly advise stay away from this site. My personal experience with it was purely disappointment as well as suspicion of deceptive behavior. Proceed with extreme caution, or even better, find a more reputable platform to meet your needs.
I highly advise to avoid this platform. My own encounter with it was only disappointment and suspicion of scamming practices. Proceed with extreme caution, or better yet, look for an honest platform for your needs.
seo hizmeti
I recognize the level of depth you provided in this write-up. It can be evident that you are an authority on this matter.
I urge you steer clear of this platform. The experience I had with it was only dismay and suspicion of scamming practices. Exercise extreme caution, or better yet, seek out a more reputable site for your needs.
Привет, дорогой читатель!
У нас на сайте можно недорого заказать и купить диплом с гарантией и доставкой покупателю в любой регион РФ
можно ли купить аттестат
Закажите диплом ВУЗа с гарантированной подлинностью и доставкой по России без предварительной оплаты – просто, надежно, выгодно!
Как можно приобрести диплом Вуза в России без предоплаты на сайте? Мы готовы доставить его в любую точку страны.
Ahaa, its fastidious dialogue about this piece of writing here at this blog, I have
read all that, so now me also commenting here.