How do I change the legacy CDN URLs of images in posts?

Hi Discourse team,

Forgive me if there’re duplicate topics but I don’t even know what keywords to search, so I started a new topic describing my problem.

Recently I got update from my CDN provider that they will abandon the legacy URLs like http://7xibfi.com1.z0.glb.clouddn.com/, and suggested me to change the URLs to my custom one http://cdn.iosre.com/ ASAP.

The problem is that most of the old posts on my website, e.g. this one, contains images with the legacy URLs, and they will be not accessible after the CDN provider abandon them.

So I guess, what I need to do, is to replace all the hosts in legacy URLs in the database with the new host, so http://7xibfi.com1.z0.glb.clouddn.com/uploads/default/original/1X/735abc46bddabe584790cf2218d5d9bbc1f2501a.png becomes http://cdn.iosre.com/uploads/default/original/1X/735abc46bddabe584790cf2218d5d9bbc1f2501a.png, which keeps the same image accessible for always.

Is there a simple and rookie-friendly way to replace all the legacy URLs with the new one?

Thanks,

Yinglu

It should (at very least) begin with changing the Discourse CDN URL in your yml file and then rebuilding discourse.

If You only have to replace links in database, there is a rake find & replace task there just for this purpose.
Documentation here:

2 Likes

I have already changed the CDN URL in app.yml and rebuilt discourse, but the legacy URLs will not be affected, right?
Seems the link is what I’m looking for; I will try it once the backup is done. Thanks for the info!

3 Likes

Search here for “rebake” (I think that the yml for might include the command).

@itsbhanusharma @pfaffman Thanks for helping!

I have tried rake and 44 posts were remapped. But I see another situation in my post, the source of the post looks like <img src="/uploads/default/213/acc63bd2c2d03f28.png" width="496" height="138"> but for readers who don’t have access to the post source and if they copy the image address, it turns out to be http://7xibfi.com1.z0.glb.clouddn.com/uploads/default/213/acc63bd2c2d03f28.png.

And I have tried to grep -r 7xibfi.com1.z0.glb.clouddn.com /var/discourse, turns out this URL appears in databases such as /var/discourse/shared/standalone/postgres_data/base/16400/361518 and css files such as /var/discourse/shared/standalone/uploads/stylesheet-cache/mobile_51397cef7eb3aa4cc8e1939c4ef7156c29bfc9e2.css, and rake doesn’t work on these files.

Any other ideas how can I change all legacy CDN URLs?

I smell something fishy here!

Can you confirm in your admin area if the s3 cdn url is blank or has any value set ?

@zogstrip some time ago there was some issue surrounding the upload urls which had brought me into a very similar situation! I remember you fixed it but can this be related to that?

Sorry, what do you mean by “s3 cdn url”?

Did you rebuild after you changed the value? (Enable a CDN for your Discourse, which is linked to in the yml file you edited says to rebuild after the change.)

No, what needs to be done is to do a rebake of the posts to fix the references to the old CDN. See Disable CDN causes old images with CDN URL can not be shown for two ways to do it. The simpler way is:

# ssh into server
cd /var/discourse
./launcher enter app
rake posts:rebake
4 Likes

EDIT: after a whole night, http://iosre.com/uploads/default/original/1X/735abc46bddabe584790cf2218d5d9bbc1f2501a.png becomes http://cdn.iosre.com/uploads/default/original/1X/735abc46bddabe584790cf2218d5d9bbc1f2501a.png, so I guess it takes a while processing all URLs? I am checking more posts to double confirm.

I did rebuild after changing DISCOURSE_CDN_URL in app.yml.

I tried running rake posts:rebake, now all images with legacy URLs such as http://7xibfi.com1.z0.glb.clouddn.com/uploads/default/original/1X/735abc46bddabe584790cf2218d5d9bbc1f2501a.png become http://iosre.com/uploads/default/original/1X/735abc46bddabe584790cf2218d5d9bbc1f2501a.png, which is hosted right on the server instead of on the CDN.

What can I do to use new CDN host cdn.iosre.com for all legacy URLs?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.