# Cloudflare R2: Navigeren door installatie en het omgaan met configuratiefouten

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

<div class="post-metadata">

### Author: ![kuaza](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuaza/32/264151_2.png) [@kuaza](https://meta.discourse.org/u/kuaza)
#### Post date: [21 april 2024 om 21:13 UTC](https://meta.discourse.org/t/cloudflare-r2-navigating-setup-and-handling-configuration-errors/305617/1 "2024-04-21T21:13:01Z")

</div>

Is there still no development on cloudflare R2? It looked good to me..

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [21 april 2024 om 21:29 UTC](https://meta.discourse.org/t/cloudflare-r2-navigating-setup-and-handling-configuration-errors/305617/2 "2024-04-21T21:29:07Z")

</div>

Did you read the note about it above? It’s incompatible with gzip files, and the was no indication that there was a plan to change they. Maybe it works with everything but uploads?

Did you try it? Did it work?

---

<div class="post-metadata">

### Author: ![kuaza](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuaza/32/264151_2.png) [@kuaza](https://meta.discourse.org/u/kuaza)
#### Post date: [21 april 2024 om 21:45 UTC](https://meta.discourse.org/t/cloudflare-r2-navigating-setup-and-handling-configuration-errors/305617/3 "2024-04-21T21:45:09Z")

</div>

Yes, I read it, but it was 2 years ago and some things may have changed.

I wanted to try it today, I activated R2 and added the site. I’m just not sure how to configure this in the discourse step. Because I haven’t been able to find where to get the key or secret codes from Cloudflare yet. I’m experimenting, maybe a little detail can help me 🙂

---

<div class="post-metadata">

### Author: ![eisammy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eisammy/32/528804_2.png) [@eisammy](https://meta.discourse.org/u/eisammy)
#### Post date: [25 april 2024 om 07:45 UTC](https://meta.discourse.org/t/cloudflare-r2-navigating-setup-and-handling-configuration-errors/305617/4 "2024-04-25T07:45:16Z")

</div>

Idem 🤔 my bucket is active but maybe discourse not has support yet but I hope for this.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [25 april 2024 om 08:57 UTC](https://meta.discourse.org/t/cloudflare-r2-navigating-setup-and-handling-configuration-errors/305617/5 "2024-04-25T08:57:25Z")

</div>

This page describes how to get the keys: [Authentication · Cloudflare R2 docs](https://developers.cloudflare.com/r2/api/s3/tokens/)

---

<div class="post-metadata">

### Author: ![kuaza](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuaza/32/264151_2.png) [@kuaza](https://meta.discourse.org/u/kuaza)
#### Post date: [26 april 2024 om 16:53 UTC](https://meta.discourse.org/t/cloudflare-r2-navigating-setup-and-handling-configuration-errors/305617/6 "2024-04-26T16:53:38Z")

</div>

I tried everything but I always get this error:

`Aws::S3::Errors::BadRequest`

I wonder what I’m missing?

When I upload an image from the R2 panel, this image opens with the special cdn url. The problem is that the image cannot be loaded on the site. I created cors and opened all methods.

```plaintext
[
  {
    "AllowedOrigins": [
      "https://SITENAME.com"
    ],
    "AllowedMethods": [
      "GET",
      "POST",
      "HEAD",
      "DELETE",
      "PUT"
    ]
  }
]

```

any ideas?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [26 april 2024 om 20:50 UTC](https://meta.discourse.org/t/cloudflare-r2-navigating-setup-and-handling-configuration-errors/305617/7 "2024-04-26T20:50:09Z")

</div>

> [@kuaza](#):
>
> Yes, I read it, but it was 2 years ago and some things may have changed.

That’s possible, but the word from Cloudflare 2 years ago was that it wasn’t likely to change, so someone who’s really excited about R2 will need to figure it out. That said, it seems possible that it might work for everything _but_ `gz` files, which I think means just backups.

But not having s3 backups seems like a lot to give up.

> [@kuaza](#):
>
> `Aws::S3::Errors::BadRequest`

That sounds like you don’t have the right key or the right endpoint.

---

<div class="post-metadata">

### Author: ![kuaza](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuaza/32/264151_2.png) [@kuaza](https://meta.discourse.org/u/kuaza)
#### Post date: [27 april 2024 om 22:57 UTC](https://meta.discourse.org/t/cloudflare-r2-navigating-setup-and-handling-configuration-errors/305617/8 "2024-04-27T22:57:44Z")

</div>

Frankly, I am currently using cloudflare on my discourse site and it is generally good to have everything in one place. So dealing with amazon can be a bit tiring when you have r2. I tried to install Amazon S3 for a while and for some reason I couldn’t get the style files to load. (okay, I’ll try again) but it would be good not to ignore clouflare, so much so when using the clouflare support forum discourse 🙂

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [28 april 2024 om 00:23 UTC](https://meta.discourse.org/t/cloudflare-r2-navigating-setup-and-handling-configuration-errors/305617/9 "2024-04-28T00:23:26Z")

</div>

> [@kuaza](#):
>
> for some reason I couldn’t get the style files to load

That’s usually when you don’t add the stanza that pushes assets to s3 (you’d also need it to make any s3-like service to work if you set the use\_s3 variable).

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [29 april 2024 om 19:58 UTC](https://meta.discourse.org/t/cloudflare-r2-navigating-setup-and-handling-configuration-errors/305617/10 "2024-04-29T19:58:19Z")

</div>

> [@kuaza](#):
>
> I tried everything but I always get this error:

> [@kuaza](#):
>
> I am currently using cloudflare on my discourse site

So did you try something else and make it work? What did you do? Can you write it up as the others in [Configure an S3 compatible object storage provider for uploads](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916)?

Does it work for backups?

---

<div class="post-metadata">

### Author: ![kuaza](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuaza/32/264151_2.png) [@kuaza](https://meta.discourse.org/u/kuaza)
#### Post date: [29 april 2024 om 21:06 UTC](https://meta.discourse.org/t/cloudflare-r2-navigating-setup-and-handling-configuration-errors/305617/11 "2024-04-29T21:06:55Z")

</div>

I tried everything I could. I tried to do it experimentally by changing the settings. But every time I get this error and when I look at it, it seems that the image has not been loaded.

> [@kuaza](#):
>
> `Aws::S3::Errors::BadRequest`

I couldn’t see anything in the error codes either. It would be nice if I could get it working, having most everything in one panel (cloudflare) would be exciting and effective.

I tried it for backup, sorry. When I failed, I turned to Amazon again. I would be very happy if there was someone more successful than me in this regard 🙂

I uploaded an image from the R2 panel and I can access it. However, I cannot upload an image via the discourse, it gives the above error.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [29 april 2024 om 21:27 UTC](https://meta.discourse.org/t/cloudflare-r2-navigating-setup-and-handling-configuration-errors/305617/12 "2024-04-29T21:27:03Z")

</div>

> [@kuaza](#):
>
> I tried everything I could. I tried to do it experimentally by changing the settings. But every time I get this error and when I look at it, it seems that the image has not been loaded.

So, maybe it doesn’t work like the documention says that it doesn’t.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [30 april 2024 om 19:21 UTC](https://meta.discourse.org/t/cloudflare-r2-navigating-setup-and-handling-configuration-errors/305617/13 "2024-04-30T19:21:25Z")

</div>

> [@pfaffman](#):
>
> So, maybe it doesn’t work like the documention says that it doesn’t.

Or maybe I sort-of owe you and apology. I do seem to have made it work, though I don’t have time to promise that I can write instructions that will allow you to make it work.

```plaintext
  DISCOURSE_USE_S3: true
  DISCOURSE_S3_REGION: 'auto'
  DISCOURSE_S3_ENDPOINT: https://=ACCOUNT_ID=.r2.cloudflarestorage.com
  DISCOURSE_S3_ACCESS_KEY_ID: '=ACCESS_KEY_ID='
  DISCOURSE_S3_SECRET_ACCESS_KEY: '=SECRET_ACCESS_KEY'
  DISCOURSE_S3_CDN_URL: '=S3_CDN_URL='
  DISCOURSE_CDN_URL: '=CDN_URL='
  DISCOURSE_S3_BUCKET: '=BUCKET='
  DISCOURSE_S3_BACKUP_BUCKET: '=BUCKET=/backups'
  DISCOURSE_BACKUP_LOCATION: 's3'

```

Don’t forget the stanza that does the rake task to push uploads to S3.

GIve this a try and see if it’ll work for you. A quick test shows that it works for uploads, assets, and backups. So, I guess the issue with gzip files no longer applies.

---

<div class="post-metadata">

### Author: ![kuaza](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuaza/32/264151_2.png) [@kuaza](https://meta.discourse.org/u/kuaza)
#### Post date: [1 mei 2024 om 14:10 UTC](https://meta.discourse.org/t/cloudflare-r2-navigating-setup-and-handling-configuration-errors/305617/15 "2024-05-01T14:10:01Z")

</div>

After correcting the region (auto) and the last url, it worked. However, there is a problem. When I recreate it, the style files are not loaded and naturally the site does not open. However, when I open it only for upload, I can upload images from the site and we can access it via the cdn url. The only problem is that I want the style files to be served from CDN. How can we do this? I think this is our only problem.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [1 mei 2024 om 15:20 UTC](https://meta.discourse.org/t/cloudflare-r2-navigating-setup-and-handling-configuration-errors/305617/16 "2024-05-01T15:20:56Z")

</div>

> [@pfaffman](#):
>
> Don’t forget the stanza that does the rake task to push uploads to S3.

You need to follow the instructions to push the assets to S3:

> [@Configure an S3 compatible object storage provider for uploads](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916/1):
>
> In order to store Discourse static assets in your Object Storage add this configuration on your app.yml under the `hooks` section:
> 
> ```plaintext
> after_assets_precompile:
> - exec:
> cd: $home
> cmd:
> - sudo -E -u discourse bundle exec rake s3:upload_assets
> - sudo -E -u discourse bundle exec rake s3:expire_missing_assets
> 
> ```

What did you use for CDN? If it was cloudflare, how did you configure it?

---

<div class="post-metadata">

### Author: ![kuaza](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuaza/32/264151_2.png) [@kuaza](https://meta.discourse.org/u/kuaza)
#### Post date: [1 mei 2024 om 15:29 UTC](https://meta.discourse.org/t/cloudflare-r2-navigating-setup-and-handling-configuration-errors/305617/17 "2024-05-01T15:29:43Z")

</div>

```plaintext
after_assets_precompile:
    - exec:
        cd: $home
        cmd:
          - sudo -E -u discourse bundle exec rake s3:upload_assets
          - sudo -E -u discourse bundle exec rake s3:expire_missing_assets

```

I added this. When I recompile, all links on the site change with the cdn url. However, these style files are not uploaded to cloudflare. So I just added the upload region setting to the app.yml file and compiled it that way. When I activate S3 from the admin, the newly uploaded images are uploaded to cloudflare R2 and access is provided.

The only problem is that when I add the s3 settings before compiling the app.yml file, the newly created style files don’t seem to be loaded. But the URLs and cdn urls change on the site.

CORS:

```plaintext
[
  {
    "AllowedOrigins": [
      "https://domain.com"
    ],
    "AllowedMethods": [
      "GET",
      "POST",
      "PUT",
      "HEAD",
      "DELETE"
    ]
  }
]

```

Could this problem have something to do with Argo? However, images are currently loading without any problems.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [1 mei 2024 om 15:35 UTC](https://meta.discourse.org/t/cloudflare-r2-navigating-setup-and-handling-configuration-errors/305617/18 "2024-05-01T15:35:45Z")

</div>

To debug, you can enter the container and try to run the rake tasks there and see what happens.

I spent about 4 hours on this yesterday, so I’m afraid my free support on this project is about up.

Don’t know about the CORS stuff. I’d allow everything from everywhere to make sure that’s not the issue. I didn’t do anything woth CORS on my test site.

> [@kuaza](#):
>
> Could this problem have something to do with Argo?

You’re running this under k8s?

---

<div class="post-metadata">

### Author: ![kuaza](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuaza/32/264151_2.png) [@kuaza](https://meta.discourse.org/u/kuaza)
#### Post date: [1 mei 2024 om 15:44 UTC](https://meta.discourse.org/t/cloudflare-r2-navigating-setup-and-handling-configuration-errors/305617/19 "2024-05-01T15:44:47Z")

</div>

Sorry for taking up your time. If I could help financially I would. I respect your time.

I don’t know what k8s is. I’m working on my own server. and I activated argo. R2 is also active. Everything is working very well now, only after the new compilation it does not load the style files (js, css etc.) into R2. I will re-run the necessary tests later and add them here. If I am successful, I will explain in detail how to find the problem or make it work.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [1 mei 2024 om 15:46 UTC](https://meta.discourse.org/t/cloudflare-r2-navigating-setup-and-handling-configuration-errors/305617/20 "2024-05-01T15:46:42Z")

</div>

What is Argo?

If this is a [standard install](https://meta.discourse.org/t/142537?silent=true) then you can run the rake command inside the container

```plaintext
./launcher enter app
rake ...

```

Are you sure that you are including the `USE_S3` part? (I guess so, as I think that’s what makes the assets expected on the CDN)

---

<div class="post-metadata">

### Author: ![kuaza](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuaza/32/264151_2.png) [@kuaza](https://meta.discourse.org/u/kuaza)
#### Post date: [1 mei 2024 om 15:59 UTC](https://meta.discourse.org/t/cloudflare-r2-navigating-setup-and-handling-configuration-errors/305617/21 "2024-05-01T15:59:07Z")

</div>

Argo: [Overview · Cloudflare Argo Smart Routing docs](https://developers.cloudflare.com/argo-smart-routing/)

I added the USE\_S3 setting before compiling, example below:

```plaintext
  DISCOURSE_USE_S3: true
  DISCOURSE_S3_REGION: 'auto'
  DISCOURSE_S3_ENDPOINT: 'https://xxxxxxxxxxxxxxxxx.eu.r2.cloudflarestorage.com'
  DISCOURSE_S3_ACCESS_KEY_ID: 'xxxxxxxxxxxxxxxxx'
  DISCOURSE_S3_SECRET_ACCESS_KEY: 'xxxxxxxxxxxxxxxxx'
  DISCOURSE_S3_CDN_URL: 'https://cdn.domain.com'
  DISCOURSE_CDN_URL: 'https://cdn.domain.com'
  DISCOURSE_S3_BUCKET: 'cloudflaredomain'
  DISCOURSE_S3_BACKUP_BUCKET: 'cloudflaredomain/backups'
  DISCOURSE_BACKUP_LOCATION: 's3'

```

After recompiling, all urls change as expected. cdn url. The only problem is, these assets are not loaded into R2. I had already added this setting:

```plaintext
  after_code:
     - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git

after_assets_precompile:
    - exec:
        cd: $home
        cmd:
          - sudo -E -u discourse bundle exec rake s3:upload_assets
          - sudo -E -u discourse bundle exec rake s3:expire_missing_assets

```

Here is the beginning of app.yml:

```plaintext
templates:
  #- "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"
  ## Uncomment the next line to enable the IPv6 listener
  #- "templates/web.ipv6.template.yml"
  #- "templates/web.ratelimited.template.yml"
  ## Uncomment these two lines if you wish to add Lets Encrypt (https)
  # - "templates/web.ssl.template.yml"
  # - "templates/web.letsencrypt.ssl.template.yml"
  - "templates/cloudflare.template.yml"

## which TCP/IP ports should this container expose?
## If you want Discourse to share a port with another webserver like Apache or nginx,
## see https://meta.discourse.org/t/17247 for details
expose:
  - "80:80" # http
  - "443:443" # https

```

Now I will try to enter the container and upload the assets to S3.

[Volgende pagina](https://meta.discourse.org/t/cloudflare-r2-navigating-setup-and-handling-configuration-errors/305617.md?page=2)
