Hey everyone, I've set up S3 for Discourse, but why are topic browsing images using COS links?

AI-generated summary

用户 danguaitu 在腾讯云COS配合EdgeOne接入Discourse时遇到问题:尽管静态资源正常通过CDN加载,但主题浏览图仍使用COS原始链接。用户提供了S3配置,其中 DISCOURSE_S3_BUCKET 设置为包含路径的 bucket/uploads/discourse。

Adam_Root 指出主要问题可能在于 DISCOURSE_S3_BUCKET 配置。该设置应仅包含存储桶名称,不应包含 /uploads/discourse 等路径部分(DISCOURSE_S3_BACKUP_BUCKET 同理)。同时,需要检查Discourse后台的 s3_cdn_url 设置,确保其正确指向EdgeOne域名及上传路径。由于 s3:upload_assets 仅处理静态资源,不会更新主题缩略图的URL,因此建议在修正配置后上传新图片测试,以确认缩略图是否使用CDN链接。

pfaffman 补充建议,如果配置无误但旧帖子仍显示错误链接,可能需要重建HTML缓存(Rebake)。可以尝试在帖子编辑界面点击扳手图标选择“rebuild html”,若有效则需批量重建所有包含图片的帖子。danguaitu 回应称这是新站,所有配置是在初始安装时一并设置的,目前仅主题浏览图显示异常,其他功能正常,并表示稍后将尝试上述建议。

Hey everyone, I’ve finished setting up S3 for Discourse. Why are the topic thumbnail images still going through the COS link? I’m using Tencent Cloud COS connected to EdgeOne.

DISCOURSE_USE_S3: true
DISCOURSE_S3_REGION: ap-beijing
DISCOURSE_S3_ENDPOINT: https://cos.ap-beijing.myqcloud.com
DISCOURSE_S3_ACCESS_KEY_ID:
DISCOURSE_S3_SECRET_ACCESS_KEY:
DISCOURSE_S3_CDN_URL: https://\*\*\*\*\*\*\*/uploads/discourse
DISCOURSE_S3_BUCKET: \*\*\*\*\*\*\*\*\*\*\*/uploads/discourse
DISCOURSE_S3_BACKUP_BUCKET: \*\*\*\*\*\*\*\*\*\*\*/discourse
DISCOURSE_BACKUP_LOCATION: s3
DISCOURSE_S3_INSTALL_CORS_RULE: false
DISCOURSE_S3_USE_ACLS: false

  after_assets_precompile:

    - exec:

        cd: $home

        cmd:

          - sudo -E -u discourse bundle exec rake s3:upload_assets

          - sudo -E -u discourse bundle exec rake s3:expire_missing_assets

Since this is a fresh installation:

I rebuilt directly, and the CSS, JS, and images were all successfully uploaded to COS. The resources are also being accessed and cached via the domain bound to EdgeOne.

However, when I check the admin backend, the topic thumbnails are still using the COS link. What could be the reason? Does anyone know how to solve this?

You’re saying that the links are for the bucket rather than the CDN? Did you have the bucket configured before the CDN? You may need to rebake those posts. You can try in the UX by clicking the wrench and “rebuild html”. If that fixes it, then you need to rebake all posts with images.

Hi, I configured these settings during installation since this is a new site. Currently, it’s only this area that isn’t displaying; everything else works fine.

I’ll try the suggested methods later.

Hi,

Since your files are uploading to COS successfully and EdgeOne is serving the static assets, the S3 connection seems to be working correctly.

One thing worth checking is your DISCOURSE_S3_BUCKET setting. It should normally contain only the bucket name, without /uploads/discourse in the path. The same applies to DISCOURSE_S3_BACKUP_BUCKET.

Also, check the s3_cdn_url setting in Discourse to make sure it points to your EdgeOne domain with the correct upload path.

Keep in mind that s3:upload_assets handles static assets, so it won’t necessarily fix URLs used for topic thumbnails.

I’d suggest uploading a new image after verifying these settings and checking whether its thumbnail uses the EdgeOne URL or the direct COS URL.

If it still points to COS, could you share an example thumbnail URL (with sensitive details hidden)? That would help identify where the URL is coming from.