Корзины Cloudflare R2 можно использовать для хранения статических ресурсов, таких как изображения и GIF-файлы, для сообщества Discourse, но их нельзя использовать для хранения резервных копий сообщества!
Введение:
Объектное хранилище Cloudflare R2 можно использовать как альтернативу Amazon S3 для хранения загружаемых файлов на вашем форуме Discourse. Ниже приведены шаги по настройке этого.
Шаги настройки:
Включить загрузку через S3: Установите флажок для включения загрузки через S3 в настройках Discourse.
ID ключа доступа S3: Введите ID ключа API для вашей корзины R2. Это идентификатор, предоставленный при создании токена API для вашей корзины.
Секретный ключ доступа: Введите секретный ключ, предоставленный при создании токена API, предоставляющего доступ к вашей корзине. Важно: Этот секретный ключ отображается только один раз, поэтому обязательно сохраните его в надежном месте.
Регион S3: Вы можете ввести любой регион, для R2 это не имеет значения.
Корзина для загрузки S3: Введите имя вашей корзины хранения R2.
Конечная точка S3: Введите ссылку API S3 для вашей корзины R2, которая имеет формат https://xxxxxx.com. Найдите эту ссылку в панели управления Cloudflare R2.
URL CDN S3: Введите публичный URL корзины хранения R2.dev для вашей корзины. Он также доступен в панели управления Cloudflare R2.
Завершение:
После настройки этих параметров ваш форум Discourse будет настроен на использование Cloudflare R2 для хранения.
Информация о бесплатном тарифном плане:
Услуга R2 от Cloudflare предоставляет бесплатный тарифный план, включающий 10 ГБ хранилища, 1 миллион загрузок и 1 миллион операций чтения в месяц.
Thank you for your feedback. I have carefully read the guide previously, and I believe the advice regarding Cloudflare R2 is incorrect. The article suggests that the Discourse community does not support Cloudflare R2 buckets. However, in reality, Cloudflare R2 is highly compatible with S3 and can perfectly handle image and file uploads and downloads for the Discourse community. This has been verified through practical application on my community (starorigin.net).
It’s much better to put the S3 settings in the yml file than configure them via the UX and store them in the database. Have you tried restoring your database to a new server?
Once you’ve set things up the recommended way, you can edit that topic or make a comment and ask someone else to.
You’re right, I use a Cloudflare R2 storage bucket to store my community’s images, GIFs, and other resources. This greatly reduces the load on the community server and speeds up page loading.
I haven’t set up automatic backups for my community to be stored in the Cloudflare R2 storage bucket because Cloudflare R2 buckets do not support storing compressed files. However, Cloudflare R2 storage can store the community’s PDFs, images, GIFs, and other static resources, which is also very good.
Thank you for the reminder, I will highlight this part.
Cloudflare R2 buckets can be used to store static assets like images and GIFs for the Discourse community, but they cannot be used to store community backups!
Just to update this post I had some gotchas that needed to be included before cloudflare worked for me.
1. Region
This wasn’t true, I had to use “auto” or the region I selected, auto is easier so use auto.
if you need to know which options you can use, try with any random string in your region and:
I also confirmed the API keys are account API keys instead of just bucket-specific keys(as mentioned in the post). Also my Discourse instance shows this:
I believe all of that is correct.
Be sure the the CDN_URL (https://pub-xxx.r2.dev)
has public read access so anonymous users can see the assets.
You can tell what’s going on in the browsers dev tools. You’ll get a bunch of 403s and red requests in the network tab if the permissions are wrong.
That’s one way to do it but that’s not the recommended way, and you’ll experience issues.
Assuming you already have your domain and cloudflare is your DNS already:
inside the S3 bucket settings there’s a public access setting.
set a unique subdomain for it. (cloudflare will automatically make the DNS record for you as well as proxying and cache)
Have you gotten backups to also work to Cloudflare R2, and is it possible(assuming backups to Cloudflare R2 are possible), to make it so it backups both locally and to Cloudflare R2?
Also does the script uploading all the assets mean that it will delete them locally(to free up storage)? Or is there a separate procedure I need to do that?
Thank you for taking the time to help me with this
I personally haven’t tried.
My forum falls under the “unsupported” category because my database is external and I have a different backup strategy than the pg_dumps the forum uses.
from what I hear backups don’t work on cloudflare but nothing stopping you from trying it.