为上传配置与 S3 兼容的对象存储提供商

:information_source: This topic covers how to configure some common S3 compatible Object Storage providers (S3 clones). See Set up file and image uploads to S3 for more details about Amazon AWS S3 configuration, which is officially supported and used internally by Discourse for our hosting services.

Provider Service Name Works with Discourse?
Amazon AWS S3 Yes
Digital Ocean Spaces Yes
Linode Object Storage Yes
Google Cloud Storage Yes
Scaleway Object Storage Yes
Vultr Object Storage Yes
BackBlaze Cloud Storage Yes*
Self-hosted MinIO Yes
Azure Blob Storage Flexify.IO Yes
Oracle Cloud Object Storage No [1]
Wasabi Object Storage Maybe
Cloudflare R2 No
Contabo Object Storage No

If you got a different service working, please add it to this wiki.

Configuration

In order to store Discourse static assets in your Object Storage add this configuration on your app.yml under the hooks section:

  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

When using object storage, you also need a CDN to serve what gets stored in the bucket. I used StackPath CDN in my testing, and other than needing to set Dynamic Caching By Header: Accept-Encoding in their configuration it works ok.

DISCOURSE_CDN_URL is a CDN that points to you Discourse hostname and caches requests. It will be used mainly for pullable assets: CSS and other theme assets.

DISCOURSE_S3_CDN_URL is a CDN that points to your object storage bucket and caches requests. It will be mainly used for pushable assets: JS, images and user uploads.

We recommend those being different and for admins to set both.

Not using a CDN (or entering the bucket URL as the CDN URL) is likely to cause problems and is not supported.

In the following examples https://falcoland-files-cdn.falco.dev is a CDN configured to serve the files under the bucket. The bucket name was set to falcoland-files in my examples.

Configuring these settings in environment variables in your app.yml is recommended because it’s how CDCK does it in their infrastructure, so it’s well-tested. Also, the task to upload assets happen after assets are compiled, which happens in a rebuild. If you want to spin a Discourse that works properly with Object Storage since the beginning you need to set the env vars so the assets are uploaded before the site starts.

Choose your provider from the list below and add these settings to the env section of your app.yml file, adjusting the values accordingly:

AWS S3

What we officially support and use internally. Their CDN offering Cloudfront also works to front the bucket files. See Set up file and image uploads to S3 for how to configure the permissions properly.

  DISCOURSE_USE_S3: true
  DISCOURSE_S3_REGION: us-west-1
  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

Digital Ocean Spaces

DO offering is good and works out of the box. It is fine to enable Restrict File Listing. Only problem is that their CDN offering is awfully broken, so you need to use a different CDN for the files. Also, you need not to install the CORS rule, as it re-installs it at every rebuild.

Example configuration:

  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
  DISCOURSE_S3_INSTALL_CORS_RULE: false 

Linode Object Storage

An extra configuration parameter, HTTP_CONTINUE_TIMEOUT, is required for Linode.

Example configuration:

  DISCOURSE_USE_S3: true
  DISCOURSE_S3_REGION: us-east-1
  DISCOURSE_S3_HTTP_CONTINUE_TIMEOUT: 0
  DISCOURSE_S3_ENDPOINT: https://us-east-1.linodeobjects.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/backup
  DISCOURSE_BACKUP_LOCATION: s3

Google Cloud Platform Storage

Listing files is broken, so you need an extra ENV to skip that so assets can work. Also skip CORS and configure it manually.

:warning: Since you can’t list files you won’t be able to list backups, and automatic backups will fail, we don’t recommend using it for backups. However, some suggest that if you change the role from Storage Legacy Object Owner to Storage Legacy Bucket Owner backups do work correctly. See this topic for Google Cloud specific discussion.

There is a third-party plugin to make the integration better at Discourse GCS Helper.

Example configuration:

  DISCOURSE_USE_S3: true
  DISCOURSE_S3_REGION: us-east1
  DISCOURSE_S3_INSTALL_CORS_RULE: false
  FORCE_S3_UPLOADS: 1
  DISCOURSE_S3_ENDPOINT: https://storage.googleapis.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/backup
  #DISCOURSE_BACKUP_LOCATION: s3

Scaleway Object Storage

Scaleway offering is also very good, and everything works fine for the most part.

:warning: Scaleway multipart uploads only support a maximum of 1,000 parts. This does not match Amazon S3, which supports a maximum of 10,000 parts. For larger instances, this will cause Discourse backups to fail and the incomplete upload may need to be manually deleted before further attempts are made. For small instances this is no issue however. Scaleway seem quite open to feedback, so if you want this limit changed you should contact them.

Note that for the DISCOURSE_S3_ENDPOINT parameter, Discourse uses the endpoint of the whole region: https://s3.{region}.scw.cloud. The “Bucket endpoint” found in your Scaleway dashboard comes in the form https://{bucketName}.s3.{region}.scw.cloud. Omit the bucket name subdomain to prevent connection errors.

Example configuration:

  DISCOURSE_USE_S3: true
  DISCOURSE_S3_REGION: fr-par
  DISCOURSE_S3_ENDPOINT: https://s3.fr-par.scw.cloud
  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

Vultr Object Storage

An extra configuration parameter, HTTP_CONTINUE_TIMEOUT, is required for Vultr.

Example configuration:

  DISCOURSE_USE_S3: true
  DISCOURSE_S3_REGION: whatever
  DISCOURSE_S3_HTTP_CONTINUE_TIMEOUT: 0
  DISCOURSE_S3_ENDPOINT: https://ewr1.vultrobjects.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/backup
  DISCOURSE_BACKUP_LOCATION: s3

Backblaze B2 Cloud Storage

You need to skip CORS and configure it manually.

There are reports of clean up orphan uploads not working correctly with BackBlaze. You must change lifecycle rules for your bucket for orphan cleanup to work.

Example configuration:

  DISCOURSE_USE_S3: true
  DISCOURSE_S3_REGION: "us-west-002"
  DISCOURSE_S3_INSTALL_CORS_RULE: false
  DISCOURSE_S3_CONFIGURE_TOMBSTONE_POLICY: false
  DISCOURSE_S3_ENDPOINT: https://s3.us-west-002.backblazeb2.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/backup
  DISCOURSE_BACKUP_LOCATION: s3

Note: During initial migration to B2, you may hit the 2500 free daily class C transactions limit. You will need to add a payment method to remove caps.

MinIO Storage Server

There are a few caveats and requirements you need to ensure are met before you can use MinIO storage server as an alternative to S3:

  1. You have a fully configured MinIO server instance
  2. You have Domain Support enabled in the MinIO configuration, for Domain driven bucket URLs. This is a mandatory setup requirement for MinIO and Discourse, as MinIO still supports the legacy S3 “path” styles which are no longer supported in Discourse.
  3. You have DNS configuration properly set up for MinIO so that bucket subdomains properly resolve to the MinIO server and the MinIO server is configured with a base domain (in this case, minio.example.com)
  4. The bucket discourse-data exists on the MinIO server and has a “public” policy set on it
  5. Your S3 CDN URL points to a properly configured CDN pointing to the bucket and cache requests, as stated earlier in this document.
  6. Your CDNs are configured to actually use a “Host” header of the core S3 URL - for example, discourse-data.minio.example.com when it fetches data - otherwise it can cause CORB problems.

Assuming the caveats and prerequisites above are met, an example configuration would be something like this:

  DISCOURSE_USE_S3: true
  DISCOURSE_S3_REGION: anything
  DISCOURSE_S3_ENDPOINT: https://minio.example.com
  DISCOURSE_S3_ACCESS_KEY_ID: myaccesskey
  DISCOURSE_S3_SECRET_ACCESS_KEY: mysecretkey
  DISCOURSE_S3_CDN_URL: https://discourse-data-cdn.example.com
  DISCOURSE_S3_BUCKET: discourse-data
  DISCOURSE_S3_BACKUP_BUCKET: discourse-backups
  DISCOURSE_BACKUP_LOCATION: s3
  DISCOURSE_S3_INSTALL_CORS_RULE: false

CORS is still going to be enabled on MinIO even if the rule is not installed by the app rebuilder - by default, it seems, CORS is enabled on all HTTP verbs in MinIO, and MinIO does not support BucketCORS (S3 API) as a result.

Azure Blob Storage with Flexify.IO

Azure Blob Storage is not an S3-compatible service, so it cannot be used with Discourse. There is a plugin, but it is broken.

The easiest way to expose an S3-compatible interface for Azure Blob Storage is to add a Flexify.IO server which translates the Azure Storage protocol into S3.

As of this writing, the service is free on Azure, and you only need a very basic (cheap) VM tier to start running it. It does, however, require a bit of setup.

  1. In Azure portal, create a new resource of Flexify.IO - Amazon S3 API for Azure Blob Storage.
  2. For light usage, the minimum VM config seems to work just fine. You can accept most of the default config. Remember to save the PEM key file when you create the VM.
  3. Browse to the Flexify.IO VM link, and enter the system. Follow the instructions by setting up the Azure Blob Storage data provider and the generated S3 end-point. Make sure that the endpoint config setting Public read access to all objects in virtual buckets is true. Copy the S3 end-point URL and keys.
  4. Press New Virtual Bucket and create a virtual bucket. It can be the same name as your Azure Blob Storage container, or it can be a different name. Link any container(s) to merge into this virtual bucket. This virtual bucket is used to expose a publicly-readable bucket via S3.
  5. By default, Flexify.IO installs a self-signed SSL certificate, while an S3 endpoint requires HTTPS. SSH into the VM using the key file (the username is by default azureuser), and replace the following files with the correct files:
  • /etc/flexify/ssl/cert.pem - replace with certificate file (PEM encoding)

  • /etc/flexify/ssl/key.pem - replace with private key file (PKCS#8 PEM encoding, that’s the one starting with BEGIN PRIVATE KEY and not BEGIN RSA PRIVATE KEY which is PKCS#1)

    These files are root so you’d have to sudo to replace them. It is best to make sure that the replacement files have the same ownership and permissions as the original ones, which means root:root and 600 permission.

  1. By default, Flexify.IO creates a root-level S3 service with multiple buckets. Discourse requires sub-domain support for buckets. Go to: <your Flexify.IO VM IP>/flexify-io/manage/admin/engines/configs/1 which will open up a hidden config page!
  2. Specify the S3 base domain (say it is s3.mydomain.com) in the Endpoint hostname field, which should be blank by default. Press Save to save the setting.
  3. Restart the Flexify.IO VM in Azure portal.
  4. In your DNS, map s3.mydomain.com and *.s3.mydomain.com to the Flexify.IO VM IP.
  5. In Discourse, set the following in the admin page (yes, there is no need for the settings to be in app.yml):
use s3: true
s3 region: anything
s3 endpoint: https://s3.mydomain.com
s3 access key: myaccesskey
s3 secret assess key: mysecret key
s3 cdn url: https://<azure-blob-account>.blob.core.windows.net/<container>
s3 bucket: <virtual bucket>
s3 backup bucket: <backup bucket>  (any container will do, as it does not require public read access and Flexify.IO will expose them automatically)
backup location: s3

Using the same bucket for production and staging is not recommended. If you do it anyway, take measures to see that your staging site doesn’t delete your production assets (set s3 disable cleanup as a minimum, and look out for it deleting production’s backups).

Wasabi

@pfaffman tried wasabi for backups, but it seemed to fail intermittently and silently, leaving backups on the hard drive and eventually filling the disk. Neither wasabi nor meta had any clues, so I don’t recommend it, though your mileage may vary. @pfaffman is now fairly certain that this problem was due to backups and automatic reboots somehow being scheduled at the same time; it was used only for backups, but seemed to work fine. If someone wants to give it a try and report here, it should work, at least for backups.

Oracle Cloud

Oracle Cloud lacks support for virtual-host style access to buckets and will not work

Cloudflare

Cloudflare’s offering is incompatible. In testing, @fearlessfrog filed a ticket with Cloudflare and in December 2022 they said:

Contabo

@tuxed tried to get Contabo Object Storage to work for S3 Compatible uploads. It seems that when uploading it prefixes the repository name in the url and he wasn’t able to get it to work.

Secure Uploads

Secure uploads are supported only for AWS S3. If your rake uploads:migrate_to_s3 fails you should enter these commands to first count and then mark as un-secure those uploads, given that you know that they do not need to be secure, in which case, you’ll need to use AWS S3.

./launcher enter app
rails c
Upload.where(secure: true).count
Upload.where(secure: true).update_all(secure:false)

  1. Oracle Cloud lacks support for virtual-host style access to buckets and will not work ↩︎

68 个赞
Defining DISCOURSE_S3_CDN_URL links to assets in S3 CDN URL
Backblaze S3 issue: duplicated uploads after delete
Migrate from AWS to Digital Ocean with 2 containers, spaces and 2 CDNs
Using Scaleway s3-compatible object storage
Extend S3 configuration for other s3 API compatible cloud storage solutions
Set up BackBlaze S3 with BunnyCDN
Setting up backup and image uploads to Backblaze B2
Upload assets to S3 after in-browser upgrade
What are the right settings to use S3 bucket (with non-Amazon URL)?
Can not access backup page and related error when restoring using GCP Object Storage
Use WebTorrent to load media objects
Issues with changing File/Image upload location to S3 Server from local storage
Hosting Optimization with Digital Ocean
Hosting Optimization with Digital Ocean
Theme modifiers: A brief introduction
Configure automatic backups for Discourse
Problem with Backblaze for backup- Failed to list backups from S3: Signature validation failed
Move from BackBlaze B2 to Digital Ocean Spaces
Which free storage for many images? also to be used for thumbnails etc
Migrate from AWS to Digital Ocean with 2 containers, spaces and 2 CDNs
Restore Failure - S3 (compatible) backup
Restore Failure - S3 (compatible) backup
Digitalocean block storage VS amazon S3
Digitalocean block storage VS amazon S3
Custom emoji don't use CDN for S3 stored assets in a few pages
Admin upgrade page doesn't load with a CDN
Install Discourse for Production Environment on Windows Server
Running Discourse on Azure Web Sites vs. Azure VM?
How to turn off S3 storage?
Access Denied error message when trying to upload images
What are the right settings to use S3 bucket (with non-Amazon URL)?
REQ: Support S3 backup to a service like Backblaze
REQ: Support S3 backup to a service like Backblaze
Using Scaleway s3-compatible object storage
Overwrite meta og:image image source to use externally public loaded images on topics?
How to store uploads with multiple web_only servers?
Can not edit topics with picture with S3 backend
Finding UI generated backup and restoring site
Looking for doc to connect discourse with digital ocean spaces
Looking for doc to connect discourse with digital ocean spaces
Looking for doc to connect discourse with digital ocean spaces
403 Error with digital ocean cdn
Link to headers (anchor links)
NoMethodError downcase s3_bucket_name absolute_base_url
What should I enter in the S3 CDN settings if I don't have a CDN?
Backing up files in Object Storage
Minio: A header you provided implies S3 functionality that is not implemented
Configure automatic backups for Discourse
S3 OVH Object Storage
File directory system
Unable to backup or navigate to backups
Uploads to AWS S3 and Configured CDN
Migration to a Self-Hosted solution from Kubernetes
How to develop discourse in a team?
Images didn't load after configuring S3 uploads
Need Azure blob storage
Use Google Cloud Storage Instead of S3
Run Discourse as docker swarm service
Move discourse uploads to free space on server
Strange behavior with Digital Ocean Spaces/S3 and lots of duplicated CORS rules for `example.com`
Can't upload PDF to S3
"canned acl" error when uploading images
AWS S3 Object Ownership
What’s your server configurations?
How to debug S3 uploads
Problems with Patreon Login, Force HTTPS, and S3 CDN (three) Issues
Cron task to sync local backups to DigitalOcean Spaces
Cron task to sync local backups to DigitalOcean Spaces
Problems with Patreon Login, Force HTTPS, and S3 CDN (three) Issues
Help restoring - system hung at midnight
Help restoring - system hung at midnight
Image upload error: The bucket does not allow ACL's
Make s3_region a string value
How can I set s3_force_path to true?
Install Discourse on a residential internet with Cloudflare Tunnel
S3 assets folder, is a cleanup needed?
BunnyCDN storage for automatic backups
BunnyCDN storage for automatic backups
Move Uploads and Backups to DigitalOcean Block Storage
Required local storage for URL referenced images vs. uploaded images?
Is DO Spaces CDN still broken? Any workarounds?
Is DO Spaces CDN still broken? Any workarounds?
Is DO Spaces CDN still broken? Any workarounds?
Basic How-To for Using MinIO storage server run by you for your Discourse Instance
Minio instead of S3?
Configure automatic backups for Discourse
S3 image bandwidth costs are getting annoying
S3 image bandwidth costs are getting annoying
Support for ImgBB image upload service
Install Discourse on Amazon Web Services (AWS)
Account creation not working with discourse_encrypt
Cannot load any images “Uncaught (in promise) no-response: no-response”
Tips on Google Cloud S3
Enable a CDN for your Discourse
Invalid URL for markdown-it-bundle
Not using volumes (or automatically using S3) when hosting with Docker
Configuring automatic backups
I have a problem with my proxy status
Inline PDF Previews
My images are not working
Getting error 422 invalid argument when configure S3 upload with GCS
SSL_connect returned=1 errno=0 peeraddr=162.243.189.2:443 state=error: certificate verify failed (Hostname mismatch)
SSL_connect returned=1 errno=0 peeraddr=162.243.189.2:443 state=error: certificate verify failed (Hostname mismatch)
Strange behavior with Digital Ocean Spaces/S3 and lots of duplicated CORS rules for `example.com`
My install broke after updating, how can I fix it?
Uploads Subdomain For Cloudflare
[PAID] Configure an S3 compatible object storage provider for uploads
Hetzner deleted my account, my server and I was left with nothing. What to do?
SSL_connect returned=1 errno=0 peeraddr=162.243.189.2:443 state=error: certificate verify failed (Hostname mismatch)
SSL_connect returned=1 errno=0 peeraddr=162.243.189.2:443 state=error: certificate verify failed (Hostname mismatch)
SSL_connect returned=1 errno=0 peeraddr=162.243.189.2:443 state=error: certificate verify failed (Hostname mismatch)
SSL_connect returned=1 errno=0 peeraddr=162.243.189.2:443 state=error: certificate verify failed (Hostname mismatch)
SSL_connect returned=1 errno=0 peeraddr=162.243.189.2:443 state=error: certificate verify failed (Hostname mismatch)
Understanding Uploads, Images, and Attachments
S3, Assets & CDN Error
Capacity planning / Resource requirements
Migrate assets to s3 rake tasks
Best option for DB and file Storage
Forum rendered unusable
Forum rendered unusable
Configure automatic backups for Discourse
Migrate Discourse broke S3 images
Configure automatic backups for Discourse
Cloud storage and cdn
Migrating uploads from S3 to local
Another discourse offline "bootstrap failed with exit code 5"
Setting up backup and image uploads to Backblaze B2
AI Plugin Build Error - 'bundle exec rake db:migrate' failed
Your Docker installation is not working correctly - no space left on device - safe to use ./launcher cleanup?
Uncaught SyntaxError: forum spins nonstop and never loads
Why is my upload limit 100mb?It's set to 500mb
Trouble with Google Bucket for backup
Did I overwrite my site settings with a cross-instance backup/restore?
S3 and Cloudfront - Setup Not Working
S3 and Cloudfront - Setup Not Working
Need tips on making my forum faster
What should be the server requirements
SSL_connect returned=1 errno=0 peeraddr=162.243.189.2:443 state=error: certificate verify failed (Hostname mismatch)
Why you should use Discourse internally for your company/team instead of Slack (4 years use case)
Make s3_region a string value
Decoupled Discourse Application - Managed Redis, Managed Postgres, and DIgital Ocean Volume with Discourse
S3 and Cloudfront - Setup Not Working
Cannot upload images in mobile discourse
Cloudflare R2: Navigating Setup and Handling Configuration Errors
Cloudflare R2: Navigating Setup and Handling Configuration Errors
Cloudflare R2: Navigating Setup and Handling Configuration Errors
S3 assets broken after moving forum
Colored loading dots because assets not uploaded
Backup request via FTP
Error when doing "bundle exec rake s3:upload_assets" - Could not locate Gemfile or .bundle/ directory
Separate S3 access keys for backups and uploads?
Secure Uploads
Topic List Previews (legacy)
Disk usage spike during backup, Discourse crashed hard :-(
Make s3_region a string value
Favicon setup: "To work correctly over a CDN it must be a png"
Change image folder to symlinked folder
Migrating uploads from S3 to local
S3 Upload Confusion: Dashboard vs. app.yml
Old installation failing upgrade
Where are Images and uploads stored?
Rebuild issue: [Cannot set dual-stack in combination with a custom endpoint.]
Problem updating data in the separate database
Backup Files Not Showing in Discourse Backend After Uploading to Cloudflare R2
Resizing images off server
Unable to setup S3 bucket
Discourse Stuck on Loading (Logs)
Discourse Stuck on Loading (Logs)
Unable to setup S3 bucket
Rebuild failure - skipping "after_assets_precompile" section of app.yml
How to add AWS Cloudfront as a Discourse CDN
Unable to setup S3 bucket
Configured s3, but i want asset to serve locally
Configured s3, but i want asset to serve locally
Set up BackBlaze S3 with BunnyCDN
Discourse s3 backup folder
SSO broken after rebuild with stable v3.3.3
How to Configure Cloudflare R2 for your Discourse Community
如何批量修改文件链接地址
Can't migrate uploads to S3
Backup discourse from the command line
Stuck and lost updating forum, problems with PG migration
Can't rebuild due to AWS SDK gem bump and new AWS Data Integrity Protections
Can't rebuild due to AWS SDK gem bump and new AWS Data Integrity Protections
S3 (not AWS) backups stopped working, presumably since an update
Troubleshooting S3 Uploads: Site hangs after rebuild, JS assets fail to load with net::ERR_... on both R2 and GCS
Inquiry About Discourse’s Support for Amazon S3 Storage
Backup discourse from the command line
Inquiry About Discourse’s Support for Amazon S3 Storage
Inquiry About Discourse’s Support for Amazon S3 Storage
Cloudflare R2 Storage Issues
Hetzner S3 support
An AWS S3 Integration with Discourse Tutorial would be nice
Issues with AWS CDN and S3
Digital Ocean Spaces (S3) "unable to sign request without credentials set"
Issues with AWS CDN and S3
Digital Ocean Spaces (S3) "unable to sign request without credentials set"
Digital Ocean Spaces (S3) "unable to sign request without credentials set"
Digital Ocean Spaces (S3) "unable to sign request without credentials set"
Digital Ocean Spaces (S3) "unable to sign request without credentials set"
为啥我的七牛云s3附件上传成功后,论坛中无法加载出来?
Imgur upload built into the post buttons
Another discourse offline "bootstrap failed with exit code 5"
Is Scaleway a good option for object storage?
Blackblaze&Cloudflare: image uploading works, but not showing in post
SMF2 Conversion and Rake to S3 Help
Backing up your forum
What causes rake uploads:fix_relative_upload_links
Running 2 hosts behind haproxy fails with random 404s
Site Blank After Rebuild
Rebuild goes into a loop
Backblaze S3 issue: duplicated uploads after delete
Migrate_to_S3 Fails on Rebake
Downloads coming from S3 even with DISCOURSE_S3_CDN_URL set
Errors trying to use custom S3 storage
Moving from one S3 bucket to another
S3 image bandwidth costs are getting annoying
Basic How-To for Using MinIO storage server run by you for your Discourse Instance
SSL error - can't upload images
Digital Ocean Spaces don’t implement the AWS S3 API for the CORS rule
Extend S3 configuration for other S3 API compatible services
How to separate uploaded files to another server
Storing Images in the cloud
Migrate_to_S3 Fails on Rebake
Cannot rebake after setting up CDN
High Availability 3 Server setup
Enable hidden setting to include S3 uploads in the backups
S3 error, when updating to 2.9.0.beta1
Azure Blob Storage Plugin
How might we better structure #howto?
Migrating uploaded files from DO to S3
Discourse as a closed wiki
Using multiple containers - what needs to be shared?
Virus scanning of uploaded files
Imgur images broken
Admin role conflates server admin and board admin
Error in rebuilding using minio as object store

大家好,

多年来我一直使用 S3 存储,且搭配 CDN。

根据我在另一个帖子中获得的建议,我今天已配置了 CloudFront CDN。

在将 CDN URL 添加到控制面板并重新烘焙 230,000+ 篇帖子之前,我想先确认一下:如果我的 CloudFront 设置有误导致一切出错,这是否符合预期?:bowing_man:t2:

目前,这是一个用户上传的图片的示例 URL:

https://greyarrows.s3.dualstack.eu-west-2.amazonaws.com/original/3X/8/3/8335cab232f512f4a979c7f0c8562e149c01b212.png

显示效果如下:

我的 CloudFront“域名”是:d1q8cepst0v8xp.cloudfront.net

如果我手动编辑上述示例 URL,将域名中的 S3 部分替换为我 CloudFront 的域名,结果如下:

https://d1q8cepst0v8xp.cloudfront.net/original/3X/8/3/8335cab232f512f4a979c7f0c8562e149c01b212.png

果然,图片仍然能正确加载:

因此,我是否可以认为,我只需要在 Discourse 控制面板中添加 S3 CDN URL d1q8cepst0v8xp.cloudfront.net,重新烘焙所有帖子,然后坐等奇迹发生?

提前感谢,CDN 对我来说完全是新事物,而且我没有开发环境来安全地测试这些 :grimacing:

4 个赞

我还启用了 s3 configure tombstone policy 设置:

Screen Shot 2021-02-14 at 21.08.39

这会有问题吗?毕竟我现在使用的是 CDN?还是说后台仍在检查原始的 S3 存储桶,而不是 CDN 的 URL?

我自然倾向于认为是后者,但再次强调,我可不敢冒险导致数十万用户的照片上传失败::scream:

:blush:

2 个赞

答案是肯定的。

为了验证这一理论,在重新烘焙数十万篇帖子之前,我进行了以下合理性检查:

  • 上传了一张图片
  • 修改了 S3 CDN 地址设置
  • 通过界面重新构建了我的测试帖子的 HTML
  • 在浏览器中刷新页面
  • 检查浏览器控制台的“网络”标签,确认图片是通过 CloudFront 加载的
  • 在新帖子中上传了一张新的测试图片
  • 再次检查浏览器控制台的“网络”标签,确认图片是通过 CloudFront 加载的

我现在正在重新烘焙所有帖子 :+1:t2:

14 个赞

感谢你的报告,Richie。我也已经运行 AWS S3 图片存储好几年了,是通过控制台消息找到这篇帖子的。但顶部的描述并没有提到你已经拥有 S3 存储、只需要 CDN 的情况。

在此记录一下我所做的操作:

  1. 进入 AWS 控制台,在“网络和内容交付”下选择 CloudFront。
  2. 点击“创建分发”按钮。
  3. 填写表单,内容相当直观。你真正需要做的只是从下拉菜单中选择存放图片的 AWS S3 存储桶。
  4. 稍等片刻,等待 CloudFront 配置完成。
  5. 在 CloudFront 分发列表的“域名”列中会出现一个形如 <乱码>.cloudfront.net 的域名。
  6. 我将该域名复制并粘贴到站点管理“文件设置”中的“s3 cdn url”字段。
  7. 我进行了一些测试:
    a. 发布了一篇包含图片上传的新帖子,确认图片确实托管在 CloudFront 上。
    b. 对某些随机的现有图片帖子执行“重建 HTML”,发现它们也使用 cloudfront.net 的图片重新构建。
  8. 一切看起来正常后,我执行了重新烘焙(rebake),由于我现在有大约五十万篇帖子,这个过程耗时数小时:
./launcher enter app
# rake posts:rebake
  1. 目前一切运行正常。它向 Sidekiq 队列中提交了大量任务,看起来每篇帖子对应一个任务,这些任务需要几天时间才能处理完毕,但系统正在逐步处理中。
18 个赞

你确定情况确实如此吗?这个网站使用了 CDN 的资源,我们并不需要清除缓存。而且这也是一个 EmberCli 的变更,理论上不应该影响生产环境 :thinking:

5 个赞

那些该死的优化器真让人头疼。如果可能的话,我建议你禁用它们,因为 Discourse 已经为每个资源提供了最优配置。这些优化器在托管 2000 年代那种“黑盒”Web 软件时表现不错,但在现代技术面前却常常彻底失效。就连 Cloudflare 那家知名公司的优化器也经常导致 Discourse 出错,所以我对其他优化器也没什么期待。它们可能今天还能用,明天就出问题,结果所有访问者看到的只是一片空白。而这一切,却没有任何实际好处。

6 个赞

有没有可能在站点设置中启用了 secure_uploads

另外,看起来这个问题今天已经有人报告并修复了,原因是与 Discourse 的兼容性问题:

6 个赞

有没有办法在管理仪表板上禁用此警告?

服务器已配置为将文件上传到 S3,但未配置 S3 CDN。

我在设置 S3 CDN 时遇到了一些问题,但直接使用 S3 并不会让我付出高昂代价,所以我完全可以接受。不过,我希望这个通知能消失,因为我完全清楚相关的后果。

2 个赞

大家好。

我想做个更新:我们现在可以使用 GCS 来设置备份了。我也在 另一个帖子 中发布了相关信息。希望这能帮助到其他正在苦苦寻找此解决方案的人。

具体怎么做呢?
启用备份的默认配置(或者你也可以在管理面板中进行设置)。

DISCOURSE_S3_BACKUP_BUCKET: falcoland-files/backup
DISCOURSE_BACKUP_LOCATION: s3

然后将存储桶权限设置为 Storage Legacy Object Owner

  1. 进入 Google Cloud 控制台中的你的项目
  2. 选择“存储”
  3. 选择你的存储桶
  4. 进入“权限”标签页
  5. 添加新权限,填写你的服务账号邮箱及对应的账号。在角色中选择 Storage Legacy Object Owner
  6. 保存并完成。

抱歉重复发帖,我只是想分享这个好消息。
谢谢。

5 个赞

如果您也能添加 Wasabi 那就太好了……

1 个赞

我曾使用 Wasabi 进行备份一段时间。就配置而言,它“开箱即用”,如果你愿意,可以试试看。

但备份会频繁地静默失败,导致备份文件仍留在本地机器上,占满磁盘空间。我查看了 Wasabi 和 Discourse 的错误日志,却始终找不到能让任何一方“修复”问题的合理解释。

我不推荐它,因为我不确定它是否“出色”。

2 个赞

谢谢!
我会看看这次的情况如何。
默认备份频率为每 7 天备份一次,最多保留 5 个备份。
我会分享后续进展。

1 个赞

我一直在做每日备份;我不记得当时打算保留多少份,但本地硬盘只能容纳几份。

2 个赞

您个人会推荐哪种存储方案?
我认为 AWS 和 Azure 对于个人项目来说不够经济实惠。
对 Azure 不太确定,但 AWS 看起来既复杂又难以预测……

1 个赞

我希望 Wasabi 至少能用于备份。Backblaze S3 价格实惠。我不确定自己是否用它上传过文件,但用于备份应该没问题(我想)。我认为 Backblaze 的唯一问题是(根据我上次测试的情况),你必须使用全局密钥(因此无法用于那些可能看到密钥的客户)。我记得最近有人发布了一个修复方案(好像是关于“旧版”的某个东西,具体位置记不清了)。如果是个人项目,我接下来会尝试这个方案。(另外,如果你在使用 Digital Ocean,Spaces 也是个不错的选择,我想。)

3 个赞

我在使用 DO,但就成本而言,Blackblaze/Wasabi 更便宜。
你用什么进行上传?

1 个赞

抱歉,我无法理解。
为什么我们需要在 app.yml 中指定设置,毕竟这些信息可以在 Discourse → 设置中直接输入?

1 个赞

我认为这是由于容器构建时处理构建资产的方式所致。设置位于环境变量中和位于数据库中时行为不同,这确实令人困惑,但这就是其工作方式。这也是一种更好的处理方式,因为它意味着您可以从命令行构建并恢复新站点。

4 个赞

我应该在哪里设置这个?我在 Discourse 管理设置中找不到它?

1 个赞