S3 图像带宽成本令人烦恼

我注意到我们网站的 S3 图片服务带宽(传输)成本持续攀升。定价为每 GB 0.09 美元,费用累积速度非常快。我想我不是唯一一个遇到此问题的网站吧?目前我每月仅向亚马逊支付 70 美元的传输费用,这甚至超过了我的虚拟机成本。S3 存储成本仅为每月 5 美元,整个问题的症结在于传输费用。

我尚未配置任何 CDN 或缓存,仅是在 Linode 虚拟机上运行一个完全通用的 Discourse,并使用 S3 图片存储桶。那些拥有大量图片的大型网站都在做什么?使用 CDN(我猜测这能降低成本)?采用 Digital Ocean Spaces 或 Minio?还是我遗漏了其他什么方案?

Using a CDN for S3 is the right approach. That will drive the transfer costs way down.

If you are in a tight budget, you may be able to use a cloudflare subdomain for that.

Hmm… looking at the bandwidth costs on Fastly and the Amazon CloudFront (and others) they are pretty much the same as the .09/GB I am paying now :frowning:

Cloudflare seems to not charge for bandwidth?? Maybe that is the thing to try then. Is there a post on how to hook up Cloudflare for S3 images CDN on Discourse? I see the s3_cdn_url but can’t find instructions on how to use it (other than I need to rebake once I set it up). Looking at Cloudflare it seems like you need to have your own domain since the DNS needs to be changed… so I would have to make a CNAME something like s3-cloudflare.mydomain.com which would point to my S3 bucket IP, and tell Cloudflare to do it’s thing on that URL, and also set s3_cdn_url to that, and then rebake?

Here is a support page I found at Cloudflare which seems to indicate this might work:

https://support.cloudflare.com/hc/en-us/articles/360013791312-Fetching-object-storage-assets-through-the-Cloudflare-CDN-using-a-Cloudflare-Worker

Anybody doing this?? I am a bit surprised there are not many sites with this issue as it is more than doubling the monthly cost for me at least.

I’m using Cloudflare on my Discourse site and it works fine. You basically route all your traffic through Cloudflare and tell it what to process or cache and that’s it. There are a few things to keep in mind though:

  1. Configure Cloudflare to NOT cache anything (set up exceptions using page rules, see below).
  2. Don’t let Cloudflare touch your Javascript - specifically, turn off Rocket Loader.
  3. I’m not sure about Brotli compression yet, I disabled it.
  4. Set up page rules to cache the avatar and upload directories as below (ignore rule #1, it’s site specific).

Cloudflare is currently caching a little over 3TB of data per month for me and it’s serving large graphics pretty fast.

If you’re more interested in a CDN I can also recommend https://www.belugacdn.com/ (I’m not affiliated with them). I use them on a large WordPress platform and performance is good, at a fraction of the cost of some other CDN platforms I looked at (those might be even more performant, but Beluga meets my needs).

@scottfsmith,你最终是否离开了 Amazon CloudFront?

我在支出不断上涨方面也遇到了类似的情况。

CloudFront 对我来说还比较新。过去几年我一直只使用 S3 存储桶,但根据这里的建议,我上个月才搭建起 CloudFront。

这一切只是将成本从 S3 的数据传输转移到了 CloudFront 的数据传输上,每月的总账单金额依然没有变化。

我发现自己正面临一个难以持续的数据传输月度账单。

我也面临同样的情况。我前不久也迁移到了 CloudFront,成本看起来也差不多。我原以为本地缓存能带来一些节省,也就是说,如果同一张图片从同一地理位置重复加载,带宽消耗会更低,但到目前为止看来并非如此。

似乎应该有其他的 CDN 可以替代 CloudFront。Discourse 所做的只是重写图片 URL,因此看起来相当通用。也许可以仅针对图片使用 Cloudflare。

我的理解也完全一样。

我们 98% 以上的流量来自英国,自然也有 98% 通过 CloudFront 从 S3 流出的流量是发往英国的。

到目前为止,我尚未看到使用 CDN 带来任何好处。如果我们的流量遍布全球,或许情况会有所不同。

接下来几天我会查阅一下 Cloudflare 的相关资料(这两家公司怎么会起这么相似的名字!),看看能否找到任何优势。

谢谢 :+1:t2:

如果您发现任何问题,请在此处跟进。我一直打算亲自查看此事。

@Richie@scottfsmith

有一些固定费用的 CDN,例如 https://www.stackpath.com/(每月 10 美元),我曾用它来测试 使用对象存储进行上传(S3 及克隆服务)。它们可能更适合您的社区。

Stackpath CDN 的费用为每月 20 美元,流量上限为 1TB,而我许多月份的用量都超过了这个限制。一旦超出,费用会跃升至每月 200 美元(上限为 20TB),这比亚马逊目前向我收取的每月约 100 美元还要高。

不过,列表中或许还有其他更合适的方案,感谢您提醒我查看这份列表。

Imgur 对所有用户免费,但目前没有为此提供的插件。

Tobey Maguire Reaction GIF

这样的插件会做什么?它只是不下载 Imgur 插件,还是会像当前系统那样,通过某个(想必存在的)API 接口将所有图片上传到 Imgur?

这对您来说价值几何?我怀疑这并不符合 CDCK 的商业模式,因为他们的付费托管服务使得 Discourse 能够被我们所有人使用,而且他们的托管服务在没有 Imgur 插件的情况下也能正常运行。

有人能确认一下这个配置在2022年是否好用吗?:slight_smile:

我们仍然在使用 Cloudflare 设置,是的。

确认无误。

您使用的设置不是全页缓存,对吗?

或者,使用 Cloudflare CDN 相较于其他 CDN 有什么特别的优势吗?

不,我们只缓存上传和头像目录;请参阅我们上面的规则。如果您尝试做其他事情,很可能会破坏 Discourse。

它是免费的 :slight_smile:

像 JS 和 CSS 这样的静态资源怎么样?

如果我们使用 本指南 来使用 CDN,那么它将与上传和头像一起提供静态资源(如果我没记错的话)。

那么,如果我们通过 Cloudflare 提供所有静态资源,Discourse 为什么会中断?

我不记得了,已经好几年了。为什么不试试然后汇报结果呢?

虽然这个帖子又被顶上来了,我也应该跟进一下……似乎 Amazon CloudFront 的定价大幅降低了。我不知道他们做了什么,但我的平均 AWS 费用从每月 80 美元左右降至每月 15 美元。这包括 S3 和 CloudFront 用于图片(仅图片)的费用,而我的网站上有大量的图片。

Cloudflare 没问题——只需禁用其 Rocket Loader 功能。

无需任何配置,它就能为我的服务器节省一半的带宽。

也许多年前 Cloudflare 与 Discourse 的兼容性不好,但今天情况并非如此。最好不要一直看到人们对此表示怀疑。如果有人遇到具体问题,他们应该在这里开一个支持帖,描述具体哪里不起作用。