How to Configure Discourse Forum S3 Backup And S3 CDN

Photo of author

By Victor Ashiedu

Published

Do you want to configure your Discourse forum S3 backup and S3 CDN but you need help configuring it? In this guide, I’ll teach you how to save your Discourse forum’s S3 backup in DigitalOcean Spaces.

When you configure Discourse to save S3 backups on a cloud storage, you may also configure the setting that allows some static Dicourse assets to be copied to the cloud storage.

Then, add a CDN to serve those static assets. This guide include steps to configure StackPack CDN to deliver the static assets saved in your cloud storage.

Step 1: Create a DigitalOcean Space

The first step is to create a DigitalOcean Spaces for your S3 backup.

Follow the steps below to create a DigitalOcean Space for your Discourse forum S3 backup.

  1. Log in to your DigitalOcean account. Then, on the top right, click the top right, click the Create button drop-down, and select Spaces.
How To Create DigitalOcean Spaces To Store Discourse Forum Backup In S3
  1. On the Create a Space page, select a data center close to your users. Then, scroll down to Finalize and Create section and give the Space a name – see the screenshot in step 3 below.
  1. Finally, to create the DigitalOcean Space to store Discourse forum backup in S3, select Restrick File Listing (default), then click Create a Space.
  1. Once you receive a confirmation that the Space has been created, move to the next section.
You will return to your DigitalOcean later. So, it is a good idea to not close the browser.
Before you proceed, note the URL of the DigitalOcean bucket you created above. You’ll need the information to create a StackPath CDN.

Step 2: Create a StackPath CDN

Before you can finally configure Discourse forum S3 backup, you need to create a CDN. This CDN is not required for the backup to work.

Rather, it is another layer of the configuration that allows some Discourse static assets to be copied to the cloud storage and served from there.

Note that the CDN you’re creating with the steps below is different from the CDN that points to your Discourse hostname.
The CDN that points to your Discourse hostname is defined in the DISCOURSE_CDN_URL. On the other hand, the CDN you’re about to set up is defined in DISCOURSE_S3_CDN_URL. This CDN points to your cloud object storage bucket.

You need the DigitalOcean Space bucket URL to create a StackPath CDN. So, ensure that you completed the steps in the last section before you proceed with the steps below:

  1. Log in to your StackPath account. If you do not have a StackPath account, create one.
  2. Once you have logged in, on the left pan, click Sites.
  1. Then, on the top menu, click Create, then select Sites from the list.
  1. On the first page of the Create Site wizard, select the second option, Select Static Assets.
  1. Then, on the next page that loads, enter the CDN URL you wish to you. You can use the naming convention <DigitalOcean-Space-Name>-cdn.yourdomainname.com.

    I am using backupstore1-cdn.www.itechguides.com.

    Secondly, ensure that Content Delivery Network (CDN) is checked. Finally, click Set Up Your Domain.
  1. When the next page loads, on the “Origin Hostname / IP Address” field, enter the full URL of your DigitalOcean Spaces URL. Finally, click Complete Setup.
To get the URL of your DigitalOcean Spaces, log in to DigitalOcean. Then, on the left pane, click the name of the project you created your Space. Finally, hover over the Space name and copy the URL.
  1. When you clicked Complete Setup in step 5, StackPath will display the DNS record you need to add to your domain.
  1. Login to your DNS provider’s site and add the CNAM record. In this example, I am using Cloudflare. If you use Cloudflare, when you add the CNAM record, make sure you uncheck Proxy status.
How To Configure Discourse Forum S3 Backup And S3 CDN
  1. Once you have completed step 7, return to StackPath and click Re-Check DNS Setup. If you got the configuration right, StackPath should display that setup is complete.

    Then, it will display the Overview section of the new CDN site you just created. You’re not done yet – see step 9 for the next task.
  1. On the left pane, click CDN. Then, on the CDN page, turn on Dynamic Caching By Header.
  1. On the Enter Header Fields field, enter Accept-Encoding and click Add. Finally, to save the host header, click Save.
  1. Next, click EdgeSSL and turn Force HTTPS Connections on.
How To Configure Discourse Forum S3 Backup And S3 CDN
  1. Finally, click Settings. Then, in the Host Header section click Add.

    Then, add the full URL for your Digital Space (DO NOT include the https://) and click Save. When you finish, make sure that the bucket URL is displayed as the Host header.
How To Configure Discourse Forum S3 Backup And S3 CDN

Step 3: Update the Discourse Configuration

Now that you have created a DigitalOcean Space, and created a StackPath CDN to point to that cloud storage, it is time to configure Discourse forum S3 backup.

In this section, you will modify the app.yml file in your Discourse Forum instance. But first, let’s put the information we need together.

In the next few steps, you will update the lines of code shown below with your own configurations.

I copied the texts below from Using Object Storage for Uploads (S3 & Clones) [Discourse official document for configuring S3 storage backup. ]
  DISCOURSE_USE_S3: true
  DISCOURSE_S3_REGION: whatever
  DISCOURSE_S3_ENDPOINT: https://nyc3.digitaloceanspaces.com
  DISCOURSE_S3_ACCESS_KEY_ID: myaccesskey
  DISCOURSE_S3_SECRET_ACCESS_KEY: mysecretkey
  DISCOURSE_S3_CDN_URL: https://falcoland-files-cdn.falco.dev
  DISCOURSE_S3_BUCKET: falcoland-files
  DISCOURSE_S3_BACKUP_BUCKET: falcoland-files/backups
  DISCOURSE_BACKUP_LOCATION: s3

Follow the steps below to find the relevant information.

  1. Back in your DigitalOcean profile, with the previous Space you created open, click Settings.
How To Configure Discourse Forum S3 Backup And S3 CDN
  1. Then, scroll down to the Endpoint section and click Copy.
How To Configure Discourse Forum S3 Backup And S3 CDN
  1. Paste the Endpoint in DISCOURSE_S3_ENDPOINT. Then, return to DigitalOcean to get the other parameters.
Note that even though I copied the endpoint without https://, I included it. Discourse requires this URL to be entered with https.
  DISCOURSE_USE_S3: true
  DISCOURSE_S3_REGION: whatever
  DISCOURSE_S3_ENDPOINT: https://nyc3.digitaloceanspaces.com
  DISCOURSE_S3_ACCESS_KEY_ID: myaccesskey
  DISCOURSE_S3_SECRET_ACCESS_KEY: mysecretkey
  DISCOURSE_S3_CDN_URL: https://falcoland-files-cdn.falco.dev
  DISCOURSE_S3_BUCKET: falcoland-files
  DISCOURSE_S3_BACKUP_BUCKET: falcoland-files/backups
  DISCOURSE_BACKUP_LOCATION: s3
  1. Back in DigitalOcean, click your project name (1). Then, scroll down to the Spaces section and hover over the Space you created earlier.

    When you hover over the name of the Space, DigitalOcean will display the region. In my example, my Space is located in NYC3 but I’ll use the lowercase – nyc3.

    It appears that this S3 backup configuration requires all lower case characters.

    Enter this information in DISCOURSE_S3_REGION – see my updated file below this screenshot. In the next steps, we will get the Access and Secret keys of the Space.
Configure Your Discourse Forum To Store Backup In S3 With DigitalOcean Spaces
  DISCOURSE_USE_S3: true
  DISCOURSE_S3_REGION: nyc3
  DISCOURSE_S3_ENDPOINT: https://nyc3.digitaloceanspaces.com
  DISCOURSE_S3_ACCESS_KEY_ID: myaccesskey
  DISCOURSE_S3_SECRET_ACCESS_KEY: mysecretkey
  DISCOURSE_S3_CDN_URL: https://falcoland-files-cdn.falco.dev
  DISCOURSE_S3_BUCKET: falcoland-files
  DISCOURSE_S3_BACKUP_BUCKET: falcoland-files/backups
  DISCOURSE_BACKUP_LOCATION: s3
  1. On the left pane of your DigitalOcean account, click API. Then, scroll down to the Spaces access keys section and click Generate New Key.
How To Configure Discourse Forum S3 Backup And S3 CDN
  1. On the page displayed by the new key wizard, enter a name for the new Spaces access key and click the confirmation button.
  1. Once the Spaces access key is created, copy the Access key (1) to the DISCOURSE_S3_ACCESS_KEY_ID. Then, copy the Secret key to DISCOURSE_S3_SECRET_ACCESS_KEY.
For security reasons, I have not included my access keys in the code beneath this screenshot. In the next steps, you will create a folder (bucket) to store your Discourse forum S3 backup in DigitalOcean Spaces.
How To Configure Discourse Forum S3 Backup And S3 CDN
  DISCOURSE_USE_S3: true
  DISCOURSE_S3_REGION: NYC3
  DISCOURSE_S3_ENDPOINT: https://nyc3.digitaloceanspaces.com
  DISCOURSE_S3_ACCESS_KEY_ID: myaccesskey
  DISCOURSE_S3_SECRET_ACCESS_KEY: mysecretkey
  DISCOURSE_S3_CDN_URL: https://falcoland-files-cdn.falco.dev
  DISCOURSE_S3_BUCKET: falcoland-files
  DISCOURSE_S3_BACKUP_BUCKET: falcoland-files/backups
  DISCOURSE_BACKUP_LOCATION: s3
  1. Back to DigitalOcean, click on your DigitalOcean project. Then, scroll down and copy the name of the Spaces bucket.

    Mine is backupstore1.

Enter the name of your Spaces bucket next to DISCOURSE_S3_BUCKET.

  DISCOURSE_USE_S3: true
  DISCOURSE_S3_REGION: nyc3
  DISCOURSE_S3_ENDPOINT: https://nyc3.digitaloceanspaces.com
  DISCOURSE_S3_ACCESS_KEY_ID: myaccesskey
  DISCOURSE_S3_SECRET_ACCESS_KEY: mysecretkey
  DISCOURSE_S3_CDN_URL: https://falcoland-files-cdn.falco.dev
  DISCOURSE_S3_BUCKET: backupstore1
  DISCOURSE_S3_BACKUP_BUCKET: falcoland-files/backups
  DISCOURSE_BACKUP_LOCATION: s3
Before you move on from DigitalOcean, open your Spaces bucket and create a folder called backups.
  1. Open your Space bucket, then click New Folder. Call the folder backups. To save the change, click the thick icon.
How To Configure Discourse Forum S3 Backup And S3 CDN
  1. Enter the name of the bucket beside DISCOURSE_S3_BUCKET. Finally, add a forward slash (/) next folder name, followed by the name of a folder.

    In my example, I used backupstore1/backups. With this naming convention, my Discourse forum S3 backup will be stored in the DigitalOcean Space backupstore1/backups

When you finish, your file should look something like what I have below. Note that I did not include my DigitalOcean’s Space access and secret keys.

  1. Next, replace “https://falcoland-files-cdn.falco.dev” below with the StackPath CDN URL you chose when you created your CDN. Mine is “https://backupstore1-cdn.www.itechguides.com”
  DISCOURSE_USE_S3: true
  DISCOURSE_S3_REGION: NYC3
  DISCOURSE_S3_ENDPOINT: https://nyc3.digitaloceanspaces.com
  DISCOURSE_S3_ACCESS_KEY_ID: myaccesskey
  DISCOURSE_S3_SECRET_ACCESS_KEY: mysecretkey
  DISCOURSE_S3_CDN_URL: https://backupstore1-cdn.www.itechguides.com
  DISCOURSE_S3_BUCKET: backupstore1
  DISCOURSE_S3_BACKUP_BUCKET: backupstore1/backups
  DISCOURSE_BACKUP_LOCATION: s3
  1. Next, SSH to your Discourse host server and open your Discourse app.yml file for editing. To open app.yml, run the following commands.
cd /var/discourse
nano containers/app.yml

The first command changes the directory to the Discourse directory. Then, the second command will open your Discourse instance’s app.yml file.

Copy the following lines below the hooks: section.

Apart from uploading your Discourse forum backup to your Object Storage, the configuration you have just completed also serves caches your Discourse pushable assets like pushable assets
The next task will upload these assets to your Object Storage.

Place the following codes immediately after your last plugin in the list. The YAML file is a tree-like data structure – white space indentation defines the structure.

So, it is important that the “after_code:” next to “hook:”, MUST be on the same line with “after_assets_precompile:” See the next screenshot below for details.

Alternatively, you can read an explanation a Discourse support team member gave me when I was trying to figure this out – the YAML file is a tree-like data structure.

  after_assets_precompile:
    - exec:
        cd: $home
        cmd:
          - sudo -E -u discourse bundle exec rake s3:upload_assets
How To Configure Discourse Forum S3 Backup And S3 CDN

Next, copy the following codes after the env: section, just after the SMTP definitions.

Remember to replace myaccesskey and mysecretkey with your DigitalOcean’s Space access and secret keys. For my configuration, I out the following below DISCOURSE_NOTIFICATION_EMAIL
DISCOURSE_USE_S3: true
DISCOURSE_S3_REGION: nyc3
DISCOURSE_S3_ENDPOINT: https://nyc3.digitaloceanspaces.com
DISCOURSE_S3_ACCESS_KEY_ID: myaccesskey
DISCOURSE_S3_SECRET_ACCESS_KEY: mysecretkey
DISCOURSE_S3_CDN_URL: https://backupstore1-cdn.www.itechguides.com
DISCOURSE_S3_BUCKET: backupstore1
DISCOURSE_S3_BACKUP_BUCKET: backupstore1/backups
DISCOURSE_BACKUP_LOCATION: s3
  1. Once you have copied the above information to your Discourse app.yml file, press the Ctrl and X buttons simultaneously. The editor will prompt you to confirm that you want to save the file – type Y and press enter.
  2. To rebuild your Discourse container, run the commands below.
cd /var/discourse
./launcher rebuild app
Wait for the container rebuild to complete. Then, after rebuilding the container for the changes you made to take effect, you need to rebake all old posts.
  1. Finally, to rebake all posts, run the commands below. If your forum has a lot of posts, the command may take hours to complete.
cd /var/discourse
./launcher enter app
rake posts:rebake

When the rebake command completes, the console will display a message similar to the highlighted portion of the screenshot below.

How To Configure Discourse Forum S3 Backup And S3 CDN
  1. To test that your Discourse forum S3 backup is saving to DigitalOcean Spaces, perform a backup of your Discourse forum instance.
  1. Finally, to complete your Discourse backup configuration, click the menu icon (1). Then, from the displayed items, click Settings (2).

When Settings opens, on the left pane, click Backup. Finally, configure things like backup frequently, time, and other essential backup configurations.

How To Configure Discourse Forum S3 Backup And S3 CDN

Frequently Asked Questions

1. Where are Discourse backups stored?

By default Discourse stores backup in the local storage. That is, the server storage you installed Discourse.

Obviously, this is not a good idea because if the server crashes, you may not be able to retrieve the backups.

So, apart from the option to store backups on the Discourse server local storage, you can also store backups in S3 storage.

With the S3 storage option, you can configure Discourse backup to store in a number of cloud storage. This guide covered steps to save Discourse backup to DigitalOcean Spaces.

For a full list of all the cloud storage that Discourse has tested, visit Using Object Storage for Uploads (S3 & Clones)

2. How do I backup Discourse?

If you want to backup Discourse to local storage follow the steps below:
a) Log in to Discourse as the site admin
b) Then, the menu on the top right and select Settings.
c) When the settings page opens, click Backups.
d) Finally, to backup Discourse, click the Backup button.

3. What are Spaces in DigitalOcean?

DigitalOcean Spaces is Object Storage that is compatible with S3. The primary purpose of DigitalOcean Spaces is to store and serve large data.

4. How much do DigitalOcean Spaces cost?

DigitalOcean Spaces start at $5/month for 250GiB. With this, you get 1TB of outbound transfer. All files you save into the Space (storage) are free.

5. What is StackPath used for?

StackPath is primarily a CDN (Content Delivery Network) service provider. When you configure a CDN with StackPath, the CDN serves static assets like CSS and StackPath files from their global network of servers.

This makes your website after since these assets are delivered to your site visitors from a StackPath CDN server closest to them.

Note that like other CDN providers, StackPath offers other services.

Conclusion

When I wrote this guide, I was creating Itechguides Community with Discourse. When I got to the point of configuring Discourse forum S3 Backup and S3 CDN, I got stuck.

Although there is documentation to perform this task, the steps are not detailed. So, I had to piece a lot of the information together with the help of the document author (Falco team).

Another Discourse community member, Jay Pfaffman was also very helpful. So, to help other people, I decided to put this guide together.

I hope you were able to configure Discourse forum S3 backup and S3 CDN with the steps in this guide. If you found the guide helpful, click on “Yes” beside the “Was this page helpful” question below.

You may also express your thoughts and opinions by using the “Leave a Comment” form at the bottom of this page.

Finally, you may find other articles on our WordPress & Websites How-Tos page helpful.

About the Author

Photo of author

Victor Ashiedu

Victor is the founder of InfoPress Media, publishers of Ilifeguides and Itechguides. With 20+ years of experience in IT infrastructure, his expertise spans Windows, Linux, and DevOps. Explore his contributions on Itechguides.com for insightful how-to guides and product reviews.

Related Articles

Get in Touch

We're committed to writing accurate content that informs and educates. To learn more, read our Content Writing Policy, Content Review Policy, Anti-plagiarism Policy, and About Us.

However, if this content does not meet your expectations, kindly reach out to us through one of the following means:

  1. Respond to "Was this page helpful?" above
  2. Leave a comment with the "Leave a Comment" form below
  3. Email us at [email protected] or via the Contact Us page.

Leave a comment

Send this to a friend