עזרה עם DISCOURSE_CDN_URL

סיכום מבוסס בינה מלאכותית

davidkingham is troubleshooting CDN and S3 configuration for their Discourse forum after switching from DigitalOcean Spaces to Amazon S3, while retaining Bunny.net as the CDN. They created a new Bunny.net pull zone with origin set to their forum URL and configured a CNAME pointing to assets.naturephotographers.network, which they assigned to DISCOURSE_CDN_URL. Despite rebuilding successfully, assets are still being served from the S3 bucket instead of the CDN. They attempted to run the s3:upload_assets rake task but encountered an error: ERROR: Ensure S3 is configured in config/discourse.conf or environment vars. In response, pfaffman clarifies that S3 credentials must be set via environment variables — configuration in the database alone is insufficient for the rake task to function. The issue appears to stem from missing or improperly configured S3 environment variables needed for asset uploads to work with the CDN.

I am trying to fix the s3/cdn settings on my site and running into problems. A little back history: I had been using digital ocean spaces with bunny.net for the cdn, I had everything set up properly in the site settings, but I had never set up DISCOURSE_CDN_URL in the app.yml because I didn’t understand how it worked or it’s importance. Recently I switched over to Amazon S3 after I started having issues with DO Spaces, but stuck with bunny.net for the cdn. I think I have that part of the changeover figured out and @pfaffman is going to help me remap the database.

The issue I’m having now is with setting the DISCOURSE_CDN_URL. What I have done is create a new pull zone on bunny for this, set the origin URL to https://community.naturephotographers.network which is my forum. I have a CNAME for this pointing to assets.naturephotographers.network. I then set DISCOURSE_CDN_URL to https://assets.naturephotographers.network and it rebuilds okay, but the assets from the site are not being pulled from the cdn of assets.naturephotographers.network, they are coming from the amazon bucket for some reason.

I tried running this rake task

  after_assets_precompile:
    - exec:
        cd: $home
        cmd:
          - sudo -E -u discourse bundle exec rake s3:upload_assets

But it fails with this error:

I, [2021-07-26T13:31:31.754617 #1]  INFO -- : > cd /var/www/discourse && sudo -E -u discourse bundle exec rake s3:upload_assets
`/root` is not writable.
Bundler will use `/tmp/bundler20210726-6572-1a099eq6572' as your home directory temporarily.
ERROR: Ensure S3 is configured in config/discourse.conf or environment vars
I, [2021-07-26T13:31:42.586559 #1]  INFO -- :
I, [2021-07-26T13:31:42.587455 #1]  INFO -- : Terminating async processes
I, [2021-07-26T13:31:42.587523 #1]  INFO -- : Sending INT to HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/13/bin/postmaster -D /etc/postgresql/13/main pid: 56
I, [2021-07-26T13:31:42.587764 #1]  INFO -- : Sending TERM to exec chpst -u redis -U redis /usr/bin/redis-server /etc/redis/redis.conf pid: 173
173:signal-handler (2021-07-26 13:31:42.588 UTC [56] LOG:  received fast shutdown request
1627306302) Received SIGTERM scheduling shutdown...
2021-07-26 13:31:42.594 UTC [56] LOG:  aborting any active transactions
2021-07-26 13:31:42.596 UTC [56] LOG:  background worker "logical replication launcher" (PID 65) exited with exit code 1
2021-07-26 13:31:42.599 UTC [6573] FATAL:  terminating autovacuum process due to administrator command
2021-07-26 13:31:42.599 UTC [6573] CONTEXT:  while vacuuming block 74749 of relation "pg_toast.pg_toast_21988"
2021-07-26 13:31:42.603 UTC [60] LOG:  shutting down
173:M 26 Jul 2021 13:31:42.630 # User requested shutdown...
173:M 26 Jul 2021 13:31:42.630 * Saving the final RDB snapshot before exiting.
2021-07-26 13:31:42.766 UTC [56] LOG:  database system is shut down
173:M 26 Jul 2021 13:31:43.123 * DB saved on disk
173:M 26 Jul 2021 13:31:43.123 # Redis is now ready to exit, bye bye...

Here are my site settings for s3/cdn:

Another interesting side note; if I have all of my s3/cdn settings in my app.yml rather than site settings it breaks my site and I have only a white page despite the settings being exactly the same, with a ton of 403 errors in the console:

  ## S3 Configuration
  DISCOURSE_USE_S3: true
  DISCOURSE_S3_REGION: us-west-1
  DISCOURSE_S3_ACCESS_KEY_ID: ***
  DISCOURSE_S3_SECRET_ACCESS_KEY: ***
  DISCOURSE_S3_CDN_URL: https://images.naturephotographers.network
  DISCOURSE_S3_BUCKET: npnimages
  DISCOURSE_S3_BACKUP_BUCKET: npn-backup
  DISCOURSE_BACKUP_LOCATION: s3

Any ideas? Thank you!

You really have to have them in the ENV vars. In the database won’t do it.