# Configure an S3 compatible object storage provider for uploads

**URL:** https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916
**Category:** Self-Hosting
**Tags:** cdn, configuring, how-to, reference
**Created:** [April 22, 2020, 10:37pm UTC](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916 "2020-04-22T22:37:37Z")
**Posts on this page:** 20
**Page:** 5

<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: [June 29, 2022, 10:45pm UTC](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916/309 "2022-06-29T22:45:28Z")

</div>

You can have a look at the javascript console. My guess is they either the CDN is wrong or they you didn’t get the precompile assets part right.

[https://community.itechguides.com/](https://community.itechguides.com/) is working now:

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

If it’s not working for you try a hard reload and/or an incognito window.

---

<div class="post-metadata">

### Author: ![Victor\_Ashiedu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/victor_ashiedu/32/264361_2.png) [@Victor\_Ashiedu](https://meta.discourse.org/u/Victor_Ashiedu)
#### Post date: [June 30, 2022, 9:50am UTC](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916/310 "2022-06-30T09:50:15Z")

</div>

The site opened for you because as of when you opened it, I had commented out the following lines from the app.yml file:

DISCOURSE\_USE\_S3: true  
DISCOURSE\_S3\_REGION: nyc3  
DISCOURSE\_S3\_ENDPOINT: [https://nyc3.digitaloceanspaces.com](https://nyc3.digitaloceanspaces.com)  
DISCOURSE\_S3\_ACCESS\_KEY\_ID: **accesskey**  
DISCOURSE\_S3\_SECRET\_ACCESS\_KEY: **secretkey**  
DISCOURSE\_S3\_CDN\_URL: [https://community-cdn.itechguides.com](https://community-cdn.itechguides.com)  
DISCOURSE\_S3\_BUCKET: itg-community-files  
DISCOURSE\_S3\_BACKUP\_BUCKET: itg-community-files/backups  
DISCOURSE\_BACKUP\_LOCATION: s3

I just re-enabled the lines and rebuilt the container. Now, the site is showing a blank page again!

The screenshot below shows where I placed the codes in my app.yml. As you can see, I placed the S3 configuration codes below DISCOURSE\_NOTIFICATION\_EMAIL

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

---

<div class="post-metadata">

### Author: ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### Post date: [June 30, 2022, 1:44pm UTC](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916/311 "2022-06-30T13:44:34Z")

</div>

What happends if you comment out `DISCOURSE_CDN_URL`?

---

<div class="post-metadata">

### Author: ![Victor\_Ashiedu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/victor_ashiedu/32/264361_2.png) [@Victor\_Ashiedu](https://meta.discourse.org/u/Victor_Ashiedu)
#### Post date: [June 30, 2022, 4:13pm UTC](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916/312 "2022-06-30T16:13:51Z")

</div>

I haven’t done that. But I have been troubleshooting and I strongly believe that I did not set up the S3 CDN correctly. I am using StackPath and I am not sure what to use in the Origin address and the Host header

 ![image](https://global.discourse-cdn.com/meta/original/4X/c/e/e/cee84562ba76613743edc9b3a23db453443b2c05.png)

---

<div class="post-metadata">

### Author: ![Victor\_Ashiedu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/victor_ashiedu/32/264361_2.png) [@Victor\_Ashiedu](https://meta.discourse.org/u/Victor_Ashiedu)
#### Post date: [June 30, 2022, 4:16pm UTC](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916/313 "2022-06-30T16:16:15Z")

</div>

Another thing I am not sure of is how to set up the file listing feature of my DigitalOcean’s Space bucket. Now, I am using Restrict Listing. Does this affect anything?

 ![image](https://global.discourse-cdn.com/meta/original/4X/c/8/1/c815d4804655269882ed93e1281e1132aff2db3f.png)

---

<div class="post-metadata">

### Author: ![Victor\_Ashiedu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/victor_ashiedu/32/264361_2.png) [@Victor\_Ashiedu](https://meta.discourse.org/u/Victor_Ashiedu)
#### Post date: [June 30, 2022, 4:39pm UTC](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916/314 "2022-06-30T16:39:32Z")

</div>

I commented out DISCOURSE\_S3\_CDN\_URL and the site loads. This confirms that my setup of the S3 CDN is the problem but I still don’t know how to set it up correctly.

I will really appreciate any help.

---

<div class="post-metadata">

### Author: ![md-misko](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/md-misko/32/126315_2.png) [@md-misko](https://meta.discourse.org/u/md-misko)
#### Post date: [June 30, 2022, 5:50pm UTC](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916/315 "2022-06-30T17:50:18Z")

</div>

Did you complete all tasks in the Configuration section?

If I remember correctly, setting DISCOURSE\_S3\_CDN\_URL in app.yml _requires_ that assets are stored on S3.

---

<div class="post-metadata">

### Author: ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### Post date: [June 30, 2022, 11:06pm UTC](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916/316 "2022-06-30T23:06:07Z")

</div>

I don’t know much how Discourse works. I’m just another copy&pasting webmaster from PHP-world, but I’m still wondering why there would be need to declare same CDN twice.

I don’t use DISCOURSE\_CDN\_URL because I have DISCOURSE\_S3\_CDN\_URL (and propably any doc I red didn’t guide to use it). So I tried.

I added `DISCOURSE_CDN_URL: <cdn-url>`. Rebuilding gave no errors, but I got error 502. When I removed it my forum worked again.

Still your issues can happend because of some misconfiguration somewhere else. But I like easy solutions, even when I’m wrong, and I’m blaiming situation when you are telling twice CDN for different needs. Or something.

---

<div class="post-metadata">

### Author: ![Victor\_Ashiedu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/victor_ashiedu/32/264361_2.png) [@Victor\_Ashiedu](https://meta.discourse.org/u/Victor_Ashiedu)
#### Post date: [July 1, 2022, 3:55pm UTC](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916/317 "2022-07-01T15:55:36Z")

</div>

DISCOURSE\_CDN\_URL and DISCOURSE\_S3\_CDN\_URL are different. While DISCOURSE\_CDN\_URL points to your forum, DISCOURSE\_S3\_CDN\_URL points to your S3 storage URL.

The idea is for DISCOURSE\_CDN\_URL to serve pullable assets like CSS while DISCOURSE\_S3\_CDN\_URL serves pushable assets like JS, images and user uploads.

I have been able to get everything working but my S3 storage CDN. Whenever I enable that bit in the app.yml file, my forum displays blank.

A look at the browser inspect element network shows that assets delivered by DISCOURSE\_S3\_CDN\_URL are showing error 404.

 ![image](https://global.discourse-cdn.com/meta/original/4X/c/4/f/c4f2bb2c892ac097e1765fbed92f54da8a50da4a.png)

This is where I am stock! I am not sure why the S3 CDN cannot deliver the assets.

---

<div class="post-metadata">

### Author: ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### Post date: [July 1, 2022, 4:14pm UTC](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916/318 "2022-07-01T16:14:18Z")

</div>

Thanks for patient explanation!

That is quite… unfamiliar for me. But as I said, I have very limited experiense. I’m using AWS as CDN thru S3/CloudFlare in WordPress but only for static files — scripts would need another setup. I reckon there is no point to compare WP and Discourse because those are fundamentally so different platforms. But I’m trying to understand principles of he concept here.

Well, I got much more now than you 😄

**EDIT** : Aaaand I was totally wrong at my setup too 😳 All JS, images, etc are served thru CDN. But I couldn’t find CSS’ there.

---

<div class="post-metadata">

### Author: ![Victor\_Ashiedu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/victor_ashiedu/32/264361_2.png) [@Victor\_Ashiedu](https://meta.discourse.org/u/Victor_Ashiedu)
#### Post date: [July 1, 2022, 4:21pm UTC](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916/319 "2022-07-01T16:21:38Z")

</div>

Yes, they are. But thanks for the update.

---

<div class="post-metadata">

### Author: ![Victor\_Ashiedu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/victor_ashiedu/32/264361_2.png) [@Victor\_Ashiedu](https://meta.discourse.org/u/Victor_Ashiedu)
#### Post date: [July 1, 2022, 4:27pm UTC](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916/320 "2022-07-01T16:27:18Z")

</div>

Hi @Jagster I really will appreciate your help.

The problem I am having now is that my site is trying to load .gz.js assets from the Object Storage CDN but the files are not there. How do I force Discours to upload those .gz.js assets to the Object Storage?

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [July 1, 2022, 4:30pm UTC](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916/321 "2022-07-01T16:30:00Z")

</div>

> [@Victor\_Ashiedu](#):
>
> How do I force Discours to upload those .gz.js assets to the Object Storage?

That’s what this bit in the guide does:

> [@Falco](#):
>
> 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
> 
> ```

---

<div class="post-metadata">

### Author: ![Victor\_Ashiedu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/victor_ashiedu/32/264361_2.png) [@Victor\_Ashiedu](https://meta.discourse.org/u/Victor_Ashiedu)
#### Post date: [July 1, 2022, 4:41pm UTC](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916/322 "2022-07-01T16:41:51Z")

</div>

I already have that line in my app.yml. I put the above code after defining the plugins. Or do I move them above the plugin lists?

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

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [July 1, 2022, 4:45pm UTC](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916/323 "2022-07-01T16:45:02Z")

</div>

That’s wrong. The `after_assets_precompile` YAML key must be under the `hooks` key.

By default we ship as:

```yaml
## Plugins go here
## see https://meta.discourse.org/t/19157 for details
hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git

```

and you want

```yaml
## Plugins go here
## see https://meta.discourse.org/t/19157 for details
hooks:
  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

```

---

<div class="post-metadata">

### Author: ![Victor\_Ashiedu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/victor_ashiedu/32/264361_2.png) [@Victor\_Ashiedu](https://meta.discourse.org/u/Victor_Ashiedu)
#### Post date: [July 1, 2022, 4:46pm UTC](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916/324 "2022-07-01T16:46:17Z")

</div>

Thank you so much, @Falco. I’ll move them now and try again.

---

<div class="post-metadata">

### Author: ![Victor\_Ashiedu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/victor_ashiedu/32/264361_2.png) [@Victor\_Ashiedu](https://meta.discourse.org/u/Victor_Ashiedu)
#### Post date: [July 1, 2022, 4:47pm UTC](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916/325 "2022-07-01T16:47:44Z")

</div>

But what about the other plugins? Is it okay to list them below

- sudo -E -u discourse bundle exec rake s3:upload\_assets ?

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [July 1, 2022, 4:48pm UTC](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916/326 "2022-07-01T16:48:56Z")

</div>

No.

It will become:

```yaml
## Plugins go here
## see https://meta.discourse.org/t/19157 for details
hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git
          - git clone https://github.com/discourse/docker_manager.git
          - git clone https://github.com/discourse/docker_manager.git
          - git clone https://github.com/discourse/docker_manager.git
          - 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

```

YAML is tree-like data structure and white space indentation defines the structure.

---

<div class="post-metadata">

### Author: ![Victor\_Ashiedu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/victor_ashiedu/32/264361_2.png) [@Victor\_Ashiedu](https://meta.discourse.org/u/Victor_Ashiedu)
#### Post date: [July 1, 2022, 5:38pm UTC](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916/327 "2022-07-01T17:38:14Z")

</div>

With the guidance you (@Falco) and @pfaffman provided, I have just successfully completed this configuration.

For other community members that wish to see my configurations. Here are the screenshots. I also wrote a comprehensive guide while I was configuring all these.

I used StackPath and DigitalOcean Spaces. My guide includes a step by step of the whole configuration. If anybody needs this guide, I will be happy to post the URL when requested.

 ![image](https://global.discourse-cdn.com/meta/original/4X/8/7/c/87ccc10a750717211a9f40a90f8c0f4a59ce4f7e.png)

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

---

<div class="post-metadata">

### Author: ![Victor\_Ashiedu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/victor_ashiedu/32/264361_2.png) [@Victor\_Ashiedu](https://meta.discourse.org/u/Victor_Ashiedu)
#### Post date: [July 1, 2022, 5:39pm UTC](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916/328 "2022-07-01T17:39:54Z")

</div>

@Falco and @pfaffman thank you both so much for your help. This is my first time configuring Discourse but I have just completed the most difficult bits (I think!). I am very grateful!.

[Previous page](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916.md?page=4)

[Next page](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916.md?page=6)
