Users report broken image URLs after changing their Discourse hostname or migrating to a new S3 bucket. andy1247008998 details how image paths remain hardcoded to the old hostname even after rebuilds or fresh boots, and notes that previews work because they use relative paths. The solution involves running discourse remap <old> <new> followed by rake posts:rebake to update stored URLs in the database — though caution is advised if the old hostname isn’t unique, as it may cause unintended replacements mpalmer. victoria faces a similar issue after renaming an S3 bucket and successfully fixes it using bundle exec ./script/discourse remap with proper PostgreSQL permissions, later confirming the fix with sudo -u discourse RAILS_ENV=production bundle exec ./script/discourse remap <old> <new>victoria. zogstrip explains that image URLs are optimized to absolute paths for performance and points to meta.discourse.org for further guidance. Inside the container, the command can be run simply as discourse remap <old> <new>zogstrip.
The URLs of the uploads are “optimized” (i.e. made absolute and use CDN when enabled) when cooking a post for performance reasons. The solution to your problem is indeed a remap. More can be found here
I’m having a similar problem with posted images on the forum I’m working on, I also have a support thread about it.
The background is a little different: I haven’t renamed the forum, but I did migrate it to docker and set up HTTPS. We use AWS and the S3 bucket’s name had forbidden characters so we renamed the bucket, but all images are still pointing to the old bucket name which doesn’t work.
Is it possible to use remap to point these images to the new bucket name? Also, are you running remap from the same place as you run rake commands?
Yes. If the old bucket name is unique enough, you can just remap on that, otherwise you’ll want to expand out the string (to include, say, the full domain) to avoid false matches. The remap process is a very blunt instrument, it just does straight-up text search-and-replace.
Yes, the full command is ./script/discourse remap <oldstring> <newstring>.
Yes, that’s the best way to do it, to avoid the possibility of someone having typed some.bucket.name into a message for some reason, and getting it rewritten accidentally.
Okay, so I ran that command, but I got this error:
/usr/local/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- thor (LoadError)
from /usr/local/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from ./script/discourse:3:in `<main>'
I’ll admit I’m not really great with ruby, not sure what is happening here. Any clues?
URGENT: FATAL: Peer authentication failed for user "discourse"
Failed to initialize site default
Rewriting all occurences of mybucket
THIS TASK WILL REWRITE DATA, ARE YOU SURE (type YES)
YES
bundler: failed to load command: ./script/discourse (./script/discourse)
PG::ConnectionBad: FATAL: Peer authentication failed for user "discourse"
/var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
...
/var/www/discourse/script/discourse:208:in `do_remap'