Configura BackBlaze S3 con BunnyCDN

Mi ci è voluto un’eternità per capire come fare tutto questo, quindi ho voluto creare questa guida per rendere le cose più semplici per gli altri. Servire le immagini in questo modo dovrebbe rendere il tuo sito più veloce nel caricamento. La mia configurazione Discourse combina un droplet DigitalOcean, BackBlaze B2 S3, BunnyCDN e la versione gratuita di Cloudflare.

Ho scelto questi servizi dopo aver fatto alcune ricerche su affidabilità, prezzi e benchmark. Sembravano le opzioni migliori per me. Cloudflare aiuta con la sicurezza, ma rallenterà leggermente il sito, almeno per quanto ne so, quindi dovresti valutarlo. Backblaze ha partnership sia con Cloudflare che con Bunny che consentono il trasferimento dati gratuito.

Anche se Cloudflare è definito una CDN, non funziona come le CDN tradizionali e probabilmente non funzionerà da solo per configurare S3 con Discourse. Potresti aver bisogno di un altro provider CDN; BunnyCDN funziona bene per me. Se qualcuno ci è riuscito solo con Cloudflare, fatemelo sapere :stuck_out_tongue:

Come impostare gli upload su S3:
Per prima cosa, devi registrarti su Backblaze, creare dei bucket e inserire i dettagli nelle impostazioni di Discourse:

Poi registrati su BunnyCDN e segui questa guida:

bunny.net - The Global Edge Platform that truly Hops (link di referral, ottengo un credito di 20$ sulla mia fattura)

Dopo aver creato la tua zona di pull su BunnyCDN, devi ottenere l’URL corretto da inserire nelle impostazioni di amministrazione di Discourse per “s3 cdn url”. Vai alla tua dashboard bunnycdn > pull zones > gestisci pull zones > clicca sulla tua zona > copia l’URL accanto a “host name”.

L’URL dovrebbe essere simile a questo: example.b-cdn.net, ma dovrai assicurarti di inserire https:// davanti, così: https://example.b-cdn.net

Salva le modifiche nell’area delle impostazioni di amministrazione di Discourse.

Premi Ctrl+F5 due volte nel tuo browser sul tuo sito Discourse.

Esegui un test caricando un’immagine nel compositore di testo di Discourse. Ispeziona l’elemento dell’immagine di test o visualizza l’origine dell’immagine per assicurarti che funzioni. L’URL dovrebbe essere diverso dal tuo dominio normale, qualcosa come example.b-cdn.net / nomefile.

Ora, ogni volta che qualcuno carica un’immagine, questa sarà nel tuo bucket Backblaze e non occuperà spazio sul tuo droplet DigitalOcean :stuck_out_tongue:

Backup degli upload su S3
Se vuoi configurare i backup di Discourse per essere salvati nel tuo bucket Backblaze, devi fare quanto segue:

Nella guida che ho pubblicato più in alto in questo thread, presta attenzione a come spiega che servono due bucket separati. Un bucket è pubblico, questo è il tuo bucket di upload per gli utenti che caricano immagini sul tuo forum. L’altro bucket è privato, questo è il tuo bucket per i backup. È importante eseguire backup automatizzati di Discourse nel caso in cui qualcosa si rompa, così potrai caricare il backup e risolverlo.

Sulla tua dashboard BunnyCDN, dovresti creare una seconda zona di pull. La tua prima zona di pull era per gli upload, questa nuova zona sarà per i backup.

dashboard bunnycdn > pull zones > aggiungi zona di pull

Segui la stessa guida a cui ho linkato prima, “Come accelerare la consegna dei file Backblaze B2 con BunnyCDN” di BunnyCDN, ma questa volta collegherai la nuova zona di pull al tuo bucket di backup invece che a quello degli upload.

Consiglio di utilizzare il “livello ad alto volume 5$/TB” nella pagina di creazione della zona di pull di BunnyCDN; penso che i backup non abbiano bisogno del livello più costoso/più veloce “livello standard 10$/TB” che ho usato per il mio bucket di upload.

Imposta le tue impostazioni di backup nell’area delle impostazioni di amministrazione di Discourse. “backup location” dovrebbe essere impostato su S3 e “s3 endpoint” dovrebbe puntare a quello che hai su Backblaze, qualcosa come questo:
s3.us-west-002.backblazeb2.com

CTRL+F5 due volte sul tuo sito per pulire la cache

Avvia un backup e attendi che termini. Poi aspetta 5 minuti e controlla la cartella dei backup su Backblaze; dovresti vedere il nuovo backup lì.

Migrazione delle immagini più vecchie:
Questo passaggio è opzionale ma consigliato, specialmente se hai poco spazio di archiviazione sul tuo server. Quindi hai tutto configurato per i nuovi caricamenti di immagini, ma anche le immagini più vecchie possono essere trasferite nei tuoi bucket. Per far funzionare questo processo, devi seguire quanto segue:

Configurazione della CDN Cloudflare
Questo passaggio è opzionale poiché Backblaze ha ottenuto una partnership che rende gratuito anche il trasferimento dati verso Bunny, ma per una sicurezza aggiuntiva e altre funzionalità, puoi far passare i dati prima attraverso Cloudflare e poi far sì che Bunny estragga i dati da dove Cloudflare li lascia cadere.

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

8 Mi Piace

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.

5 Mi Piace

You can migrate old files using the rake task.

1 Mi Piace

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.

The task is:

cd /var/discourse
./launcher enter app
rails c
rake uploads:migrate_to_s3
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.

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

1 Mi Piace

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

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?

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.

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.

DISCOURSE_S3_CDN_URL: 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.

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

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

1 Mi Piace

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.

1 Mi Piace

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

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)

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

3 Mi Piace

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

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.

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.

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.

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