# Cloudflare R2: Navigating Setup and Handling Configuration Errors

**URL:** https://meta.discourse.org/t/cloudflare-r2-navigating-setup-and-handling-configuration-errors/305617
**Category:** Self-hosting
**Tags:** s3
**Created:** [April 21, 2024, 9:13pm UTC](https://meta.discourse.org/t/cloudflare-r2-navigating-setup-and-handling-configuration-errors/305617 "2024-04-21T21:13:01Z")
**Posts on this page:** 1
**Showing post:** 40

<div class="post-metadata">

### Author: ![kamaljain](https://avatars.discourse-cdn.com/v4/letter/k/c2a13f/32.png) [@kamaljain](https://meta.discourse.org/u/kamaljain)
#### Post date: [August 26, 2024, 3:49pm UTC](https://meta.discourse.org/t/cloudflare-r2-navigating-setup-and-handling-configuration-errors/305617/40 "2024-08-26T15:49:48Z")

</div>

Hi everyone,

I wanted to share my experience and steps on how I successfully configured Cloudflare R2 for both uploads and backups in my Discourse forum. I hope this helps others who are looking to use Cloudflare R2 with Discourse.

### Setup Overview:

- **Platform:** Discourse (Bitnami installation)
- **Bucket:** Cloudflare R2
- **Custom Domain:** Set up for serving files publicly
- **Configuration:** Done entirely through Discourse site settings (no environment variables were touched)

### Step-by-Step Guide:

1. **Create a Cloudflare R2 Bucket:**

- Log in to your Cloudflare account and navigate to R2 storage.
- Create a new bucket for your Discourse uploads (e.g., `forum-uploads`).
- Note down the **Bucket S3 API URL** , **Access Key ID** , and **Secret Access Key**.

1. **Set Up Custom Domain for CDN:**

- To serve your R2 bucket content publicly, create a custom domain in Cloudflare.
- For example, I used `forumfiles.example.in`.
- Make sure to configure DNS settings to point to Cloudflare’s provided CNAME. Since I have a domain on cloudflare, it did it for me.

1. **Configure Discourse Site Settings:**
  - **s3\_bucket:** Your R2 bucket name (e.g., `forum-uploads`).
  - **s3\_region:** Set as US East (N. Virginia). There was no option of auto.
  - **s3\_endpoint:** Use your **Bucket S3 API URL** provided by Cloudflare (e.g., `https://<your-bucket-unique-id>.r2.cloudflarestorage.com`).
  - **s3\_access\_key\_id:** Your R2 **Access Key ID**.
  - **s3\_secret\_access\_key:** Your R2 **Secret Access Key**.
  - **s3\_cdn\_url:** Your custom domain for CDN (e.g., `https://forumfiles.example.in`).

- Ensure that **enable s3 backups** and **enable s3 uploads** are checked.

1. **Adjust Permissions and CORS:**

- Set your R2 bucket to private and configure a CORS policy:

```plaintext
[
  {
      "AllowedHeaders": ["*"],
      "AllowedMethods": ["GET", "POST", "PUT", "HEAD"],
      "AllowedOrigins": ["*"],
      "ExposeHeaders": ["ETag"],
      "MaxAgeSeconds": 3000
  }
]

```

- This ensures that the uploads work correctly without CORS issues.

1. **Testing the Setup:**

- Upload a test file or image through your Discourse forum to verify that uploads are working correctly.
- Check if the files are accessible via your custom domain (e.g., `https://forumfiles.example.in/original/1X/...`).
- Check the backups, I could successfully get backups executed. Cross checked at R2 bucket and its also listed in the site settings.

### Conclusion:

By following these steps, I was able to integrate Cloudflare R2 with Discourse seamlessly, handling both uploads and backups efficiently. If you have any questions or run into issues, feel free to ask!

---

_[View the full topic](https://meta.discourse.org/t/cloudflare-r2-navigating-setup-and-handling-configuration-errors/305617)._
