# Set up BackBlaze S3 with BunnyCDN

**URL:** https://meta.discourse.org/t/set-up-backblaze-s3-with-bunnycdn/159135
**Category:** Sysadmins
**Tags:** how-to
**Created:** [July 29, 2020, 3:33am UTC](https://meta.discourse.org/t/set-up-backblaze-s3-with-bunnycdn/159135 "2020-07-29T03:33:57Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Bill](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bill/32/159342_2.png) [@Bill](https://meta.discourse.org/u/Bill)
#### Post date: [July 29, 2020, 3:33am UTC](https://meta.discourse.org/t/set-up-backblaze-s3-with-bunnycdn/159135/1 "2020-07-29T03:33:57Z")

</div>

It took me forever to figure out how to do all of this, so I wanted to make this guide to make it easier for people. Serving your images this way is supposed to make your website load faster. My Discourse setup combines a DigitalOcean droplet, BackBlaze B2 S3, BunnyCDN, and the free version of Cloudflare.

I went with these services after doing a bit of research into reliability, pricing, and benchmarks. They looked like the best options for me. Cloudflare helps with security, but will also slow the site down slightly from what I understand so you should look into that. Backblaze has partnerships with both cloudflare and bunny that allow for free data transfer.

> **[B2/Cloudflare Partnership Offers the Lowest Cost Media Serving Platform](https://www.backblaze.com/blog/backblaze-and-cloudflare-partner-to-provide-free-data-transfer/)**
>
> Backblaze and Cloudflare have partnered to offer free data transfer between the two. What does this partnership mean for you, and how can you use it?

Although Cloudflare is called a CDN, it doesn’t work like regular CDN’s and it will probably not work alone for setting up S3 with Discourse. You will possibly need another CDN provider, BunnyCDN works well for me. If someone has successfully done it with just Cloudflare, let me know how 😛

**How to set uploads to S3:**  
First, you need to sign up at Backblaze, then make buckets, and insert the details into the Discourse settings:

> **[Low Cost, High Performance S3 Compatible Object Storage](https://www.backblaze.com/cloud-storage)**
>
> Backblaze B2 provides unlimited data storage in the cloud at 1/5th the cost of Amazon S3, Microsoft Azure, and Google Cloud.

> [@Setting up backup and image uploads to Backblaze B2](https://meta.discourse.org/t/setting-up-backup-and-image-uploads-to-backblaze-b2/150348):
>
> So I was following the [Digital Ocean Spaces guide](https://meta.discourse.org/t/setting-up-backup-and-image-uploads-to-digitalocean-spaces/92502), and I started looking around for cheaper providers for my (very) small community. I noticed [this old post](https://meta.discourse.org/t/extend-s3-configuration-for-other-s3-api-compatible-cloud-storage-solutions/20593/21) which confused me, because I had just looked at Backblaze B2 and saw that it was S3 compatible. Turns out they launched the feature 30 minutes before I had looked (what luck!). So I have decided to write a quick guide on how I got it to work with my current community: Step 1: Configuring Backblaze B2 Cloud Storage Create Account Go to [B2 …](https://www.backblaze.com/b2/cloud-storage.html)

Then you sign up with BunnyCDN and follow this guide:

[bunny.net - The Global Edge Platform that truly Hops](https://bunnycdn.com/?ref=qcp86164sq) (referral link, I get a 20$ credit on my bill)

> **[How to speed up your Backblaze B2 file delivery with Bunny CDN](https://support.bunny.net/hc/en-us/articles/360018649972-How-to-speed-up-your-Backblaze-B2-file-delivery-with-Bunny-CDN)**
>
> Bunny CDN provides a fast and easy way to speed up your Backblaze B2 bucket, as well as save thousands of dollars on bandwidth costs. This guide will show you how to setup Bunny CDN in 3 easy steps...

After you create your BunnyCDN pull zone, you need to get the correct url to insert into your Discourse admin backend setting for “s3 cdn url”. Go to your bunnycdn dashboard\>pull zones\>manage pull zones\>click your zone\> copy the url next to “host name”

The url should like something like this: [example.b-cdn.net](http://example.b-cdn.net) but you will need to make sure you put https:// in front of it like this: [https://example.b-cdn.net](https://example.b-cdn.net)

Save the changes in Discourse admin setting area.

Press ctrl+f5 twice in your browser on your discourse site.

Do a test by uploading an image in the discourse text composer. Inspect the test image element, or view the images source to make sure it worked. The url should look different than your normal domain, it should be something like [example.b-cdn.net](http://example.b-cdn.net) / filename

Now, every time someone uploads an image, it will be in your backblaze bucket and not taking up room on your digitalocean droplet 😛

**Backup Uploads to S3**  
If you want to setup your Discourse backups to go into your backblaze bucket, you need to do this:

In the guide I posted higher in this thread, pay attention to how he explains you need two separate buckets. One bucket is public, this is your uploads bucket for your users to upload images on your forum. The other bucket is private, this is your backup’s bucket. It’s important to make automated backups of Discourse just in case anything breaks, then you can load your backup and fix it.

On your BunnyCDN dashboard, you should create a second pull zone. Your first pull zone was for uploads, this new pull zone will be for backups.

bunnycdn dashboard\>pull zones\>add pull zone

Follow the same guide I linked to earlier, BunnyCDN’s “How to Speed up your Backblaze B2 file delivery with BunnyCDN” but this time you would link the new pull zone to your backup bucket instead of your uploads bucket.

I recommend using the “high volume tier 5$/TB” on BunnyCDN’s pull zone creation page, I think backups don’t need the more expensive/faster tier “standard tier 10$/TB” that I used my for uploads bucket.

Set your backup settings in the discourse admin settings area. “backup location” should be set to S3 and “s3 endpoint” should point to what you have at backblaze, something like this:  
[s3.us-west-002.backblazeb2.com](http://s3.us-west-002.backblazeb2.com)

CTRL+F5 twice on your website to clear cache

Start a backup, let it finish. Then wait 5 minutes and check your backblaze backups folder, you should see the new backup there.

**Migrating Older Images:**  
This step is optional but recommended, especially if your low on storage on your server. So you got everything set up for new image uploads, but older images can be transfered to your buckets as well. To make this process work, you need to follow this:

> [@AntiMetaman](#):
>
> I have my backups working with S3 as well. So I have old and new uploads working with S3. I am using Cloudflare for SSL, DDoS, BunnyCDN for the upload and backup pull zones, and BackBlaze for the S3 storage. I’m all good now!
> 
> Note that it’s better to define the env variables in the app.yml as shown here: [Using Object Storage for Uploads (S3 Clones)](https://meta.discourse.org/t/using-object-storage-for-uploads-s3-clones/148916)
> 
> Then rebuild so that the S3 configuration is globally defined and not just in admin panel. This way, when you migrate old files to s3, you can do it easier with 3 commands:
> 
> `./launcher enter app`  
> `rake uploads:migrate_to_s3`  
> `rake posts:rebake`

**Setting up Cloudflare CDN**  
This step is optional since Backblaze has gotten a partnership that makes data transfer to Bunny free too, but for additional security and other features, you can make the data go through Cloudflare first, and then make Bunny pull the data from where Cloudflare drops it.

[https://help.backblaze.com/hc/en-us/articles/217666928-Using-Backblaze-B2-with-the-Cloudflare-CDN](https://help.backblaze.com/hc/en-us/articles/217666928-Using-Backblaze-B2-with-the-Cloudflare-CDN)

---

<div class="post-metadata">

### Author: ![AntiMetaman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/antimetaman/32/186978_2.png) [@AntiMetaman](https://meta.discourse.org/u/AntiMetaman)
#### Post date: [July 29, 2020, 3:40am UTC](https://meta.discourse.org/t/set-up-backblaze-s3-with-bunnycdn/159135/2 "2020-07-29T03:40:49Z")

</div>

Just wanted to say I have done what Bill did, and confirm it works! The only catch is that it works for new files and not the old ones. The cool thing about Bill’s method is that it didn’t even need a rebuild. However, I hope that someone figures out how to get the old files to work with S3 too.

Backups don’t work either btw. At least not for me and I did the same exact thing as Bill.

---

<div class="post-metadata">

### Author: ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)
#### Post date: [July 29, 2020, 5:55am UTC](https://meta.discourse.org/t/set-up-backblaze-s3-with-bunnycdn/159135/3 "2020-07-29T05:55:19Z")

</div>

You can migrate old files using the rake task.

---

<div class="post-metadata">

### Author: ![AntiMetaman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/antimetaman/32/186978_2.png) [@AntiMetaman](https://meta.discourse.org/u/AntiMetaman)
#### Post date: [July 29, 2020, 1:15pm UTC](https://meta.discourse.org/t/set-up-backblaze-s3-with-bunnycdn/159135/4 "2020-07-29T13:15:24Z")

</div>

If you mean this command, I already tried it and it didn’t upload the old assets:

`sudo -E -u discourse bundle exec rake s3:upload_assets`

I rebaked my posts too, but no dice.

---

<div class="post-metadata">

### Author: ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)
#### Post date: [July 29, 2020, 2:44pm UTC](https://meta.discourse.org/t/set-up-backblaze-s3-with-bunnycdn/159135/5 "2020-07-29T14:44:44Z")

</div>

The task is:

```plaintext
cd /var/discourse
./launcher enter app
rails c
rake uploads:migrate_to_s3

```

---

<div class="post-metadata">

### Author: ![Bill](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bill/32/159342_2.png) [@Bill](https://meta.discourse.org/u/Bill)
#### Post date: [July 29, 2020, 3:21pm UTC](https://meta.discourse.org/t/set-up-backblaze-s3-with-bunnycdn/159135/6 "2020-07-29T15:21:13Z")

</div>

```plaintext
cd /var/discourse
./launcher enter app
rails c
rake uploads:migrate_from_s3

```

Does this work for you @AntiMetaman ?  
I will add it to the guide if so.

I will try to figure out how to get backups to work correctly, and update the guide with that as well. I know for sure I need to make a second pull zone.

---

<div class="post-metadata">

### Author: ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)
#### Post date: [July 29, 2020, 4:23pm UTC](https://meta.discourse.org/t/set-up-backblaze-s3-with-bunnycdn/159135/7 "2020-07-29T16:23:48Z")

</div>

I have backups working fine with backblaze … What issue are you facing?

---

<div class="post-metadata">

### Author: ![Bill](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bill/32/159342_2.png) [@Bill](https://meta.discourse.org/u/Bill)
#### Post date: [July 29, 2020, 4:45pm UTC](https://meta.discourse.org/t/set-up-backblaze-s3-with-bunnycdn/159135/8 "2020-07-29T16:45:26Z")

</div>

My backups are working fine with this method as well. You must have something set wrong. I will update the guide right now on how I set up backups. @AntiMetaman

---

<div class="post-metadata">

### Author: ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)
#### Post date: [July 29, 2020, 5:01pm UTC](https://meta.discourse.org/t/set-up-backblaze-s3-with-bunnycdn/159135/9 "2020-07-29T17:01:55Z")

</div>

> [@Bill](#):
>
> You must have something set wrong.

I’m sorry, I don’t follow this? How come I have something working fine when you are suggesting that I have something set wrong?

---

<div class="post-metadata">

### Author: ![AntiMetaman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/antimetaman/32/186978_2.png) [@AntiMetaman](https://meta.discourse.org/u/AntiMetaman)
#### Post date: [July 29, 2020, 5:17pm UTC](https://meta.discourse.org/t/set-up-backblaze-s3-with-bunnycdn/159135/10 "2020-07-29T17:17:00Z")

</div>

He’s talking to me @itsbhanusharma. My backups aren’t working. My configuration is the same as Bill’s. I didn’t use a separate pull zone for the backup bucket though so maybe that’s why. I just have the name of the backup bucket in the env variables.

I’ll try Bhanu’s suggestion to migrate the s3 assets later.

---

<div class="post-metadata">

### Author: ![AntiMetaman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/antimetaman/32/186978_2.png) [@AntiMetaman](https://meta.discourse.org/u/AntiMetaman)
#### Post date: [July 29, 2020, 5:55pm UTC](https://meta.discourse.org/t/set-up-backblaze-s3-with-bunnycdn/159135/11 "2020-07-29T17:55:15Z")

</div>

I created two pull zones, one for each of the buckets (upload and backup). I started a backup from my admin panel but it failed. The only thing that Discourse knows is the name of the backup bucket.

 ![image](https://global.discourse-cdn.com/meta/original/3X/4/a/4a9f4e91e4c01302b86ea1c5eda46dbdb1ea5b28.png)

> DISCOURSE\_S3\_CDN\_URL: [https://duelistsunite.b-cdn.net](https://duelistsunite.b-cdn.net)  
> DISCOURSE\_S3\_BUCKET: s3omega  
> DISCOURSE\_S3\_BACKUP\_BUCKET: s3omegabackup  
> DISCOURSE\_BACKUP\_LOCATION: s3

Not sure what I’m missing here. Is there a S3\_CDN\_BACKUP\_URL ? given that the url is different for the backup.

@itsbhanusharma Also, I tried your method, but `migrate_from_S3` is undefined.

 ![image](https://global.discourse-cdn.com/meta/original/3X/a/1/a148800ea2bbd395a5afa10ec653869db048d9c7.png)

Also, I wasn’t sure if you meant `migrate_to_s3` so I tried that too, but that was also undefined.

---

<div class="post-metadata">

### Author: ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)
#### Post date: [July 30, 2020, 2:53am UTC](https://meta.discourse.org/t/set-up-backblaze-s3-with-bunnycdn/159135/12 "2020-07-30T02:53:48Z")

</div>

I’m sorry for the confusion, I meant `rake uploads:migrate_to_s3`

---

<div class="post-metadata">

### Author: ![AntiMetaman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/antimetaman/32/186978_2.png) [@AntiMetaman](https://meta.discourse.org/u/AntiMetaman)
#### Post date: [July 30, 2020, 2:54am UTC](https://meta.discourse.org/t/set-up-backblaze-s3-with-bunnycdn/159135/13 "2020-07-30T02:54:58Z")

</div>

![image](https://global.discourse-cdn.com/meta/original/3X/4/a/4aeb7f484b6c316b9594dbacd2cb16f840a47c8a.png)

It aborts the rake it seems because it adds the `amazonaws.com` to the url when in fact, that is incorrect. This is the problem. If you use a S3 that’s not amazon, then the rake won’t work since it’s hardcoded to change the url.

---

<div class="post-metadata">

### Author: ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)
#### Post date: [July 30, 2020, 3:09am UTC](https://meta.discourse.org/t/set-up-backblaze-s3-with-bunnycdn/159135/14 "2020-07-30T03:09:54Z")

</div>

Can you confirm/deny if you added settings to the app.yml env section or did you add the settings to admin \> settings page?

---

<div class="post-metadata">

### Author: ![AntiMetaman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/antimetaman/32/186978_2.png) [@AntiMetaman](https://meta.discourse.org/u/AntiMetaman)
#### Post date: [July 30, 2020, 2:42pm UTC](https://meta.discourse.org/t/set-up-backblaze-s3-with-bunnycdn/159135/17 "2020-07-30T14:42:40Z")

</div>

I have my backups working with S3 as well. So I have old and new uploads working with S3. I am using Cloudflare for SSL, DDoS, BunnyCDN for the upload and backup pull zones, and BackBlaze for the S3 storage. I’m all good now!

Note that it’s better to define the env variables in the app.yml as shown here: [Configure an S3 compatible object storage provider for uploads](https://meta.discourse.org/t/using-object-storage-for-uploads-s3-clones/148916)

Then rebuild so that the S3 configuration is globally defined and not just in admin panel. This way, when you migrate old files to s3, you can do it easier with 3 commands:

`./launcher enter app`  
`rake uploads:migrate_to_s3`  
`rake posts:rebake`

---

<div class="post-metadata">

### Author: ![paulrudy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paulrudy/32/259901_2.png) [@paulrudy](https://meta.discourse.org/u/paulrudy)
#### Post date: [September 4, 2020, 9:47pm UTC](https://meta.discourse.org/t/set-up-backblaze-s3-with-bunnycdn/159135/18 "2020-09-04T21:47:08Z")

</div>

> Not sure what I’m missing here. Is there a S3\_CDN\_BACKUP\_URL ? given that the url is different for the backup.

Did you resolve this question? I’m also not clear where to put the url for the pull zone that points to the backup bucket.

Edit: Am I correct in realizing that the CDN is only needed for the uploads bucket? The guide on this topic suggests a second CDN pull zone should be created for the backup bucket. If that’s wrong, perhaps the guide should be updated @Bill

---

<div class="post-metadata">

### Author: ![AntiMetaman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/antimetaman/32/186978_2.png) [@AntiMetaman](https://meta.discourse.org/u/AntiMetaman)
#### Post date: [September 4, 2020, 10:11pm UTC](https://meta.discourse.org/t/set-up-backblaze-s3-with-bunnycdn/159135/19 "2020-09-04T22:11:35Z")

</div>

Apparently it only needs the backup bucket name. From the name it can get the backup S3 url since it will be the same as the upload except for the name difference. This is why you don’t have to define a separate S3 backup url. This is of course assuming that both buckets are in the same S3 service.

---

<div class="post-metadata">

### Author: ![paulrudy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paulrudy/32/259901_2.png) [@paulrudy](https://meta.discourse.org/u/paulrudy)
#### Post date: [September 4, 2020, 10:27pm UTC](https://meta.discourse.org/t/set-up-backblaze-s3-with-bunnycdn/159135/20 "2020-09-04T22:27:19Z")

</div>

But if the backup bucket is private, how would the CDN access it? I’m new to CDN’s and may be missing something, but I suspect that Discourse doesn’t use the CDN at all to back up.

---

<div class="post-metadata">

### Author: ![AntiMetaman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/antimetaman/32/186978_2.png) [@AntiMetaman](https://meta.discourse.org/u/AntiMetaman)
#### Post date: [September 4, 2020, 10:31pm UTC](https://meta.discourse.org/t/set-up-backblaze-s3-with-bunnycdn/159135/21 "2020-09-04T22:31:12Z")

</div>

They do. I went to my backup bucket and I see the backup uploaded there. It’s private but discourse can access it. You can setup permissions if the url is there. You can make it so only your site can access the bucket too or any https source.

---

<div class="post-metadata">

### Author: ![paulrudy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paulrudy/32/259901_2.png) [@paulrudy](https://meta.discourse.org/u/paulrudy)
#### Post date: [September 4, 2020, 10:47pm UTC](https://meta.discourse.org/t/set-up-backblaze-s3-with-bunnycdn/159135/22 "2020-09-04T22:47:19Z")

</div>

Can you verify that the backup went through the CDN, vs directly from your Discourse install to BackBlaze B2?

[Next page](https://meta.discourse.org/t/set-up-backblaze-s3-with-bunnycdn/159135.md?page=2)
