Configure an S3 compatible object storage provider for uploads

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/ is working now:

image

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

2 Likes

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
DISCOURSE_S3_ACCESS_KEY_ID: accesskey
DISCOURSE_S3_SECRET_ACCESS_KEY: secretkey
DISCOURSE_S3_CDN_URL: 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


a

1 Like

What happends if you comment out DISCOURSE_CDN_URL?

1 Like

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

1 Like

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?

1 Like

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.

1 Like

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.

2 Likes

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.

2 Likes

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.

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

4 Likes

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 :smile:

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

1 Like

Yes, they are. But thanks for the update.

1 Like

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?

1 Like

That’s what this bit in the guide does:

1 Like

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?

1 Like

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

By default we ship as:

## 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

## 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
1 Like

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

2 Likes

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

  • sudo -E -u discourse bundle exec rake s3:upload_assets ?
1 Like

No.

It will become:

## 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.

3 Likes

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.

2 Likes

@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!.

3 Likes